theKashey/rewiremock

Using mock trackers

darcyrush opened this issue · 2 comments

I have figured out how to mock the dependencies in my SUTs using this library, but I want to to actually use some sort of mock tracker to test calls etc. I cannot figure out how to include them from this library?

import rewiremock from "rewiremock";

const mock = rewiremock.mock() // This isn't a thing
const sut = rewiremock.proxy<any>(
  './path/to/sut.ts',
  {
    './dependency': { mock }
  }
)

sut.func()

assert(mock.called.once, true)

rewiremock does not defines own helpers for this and proposing you to use something different, like sinon.
You may tell rewritemock which solution to use via rewiremock.stubFactory, but that's all.

import sinon from 'sinon';
import rewiremock from 'rewiremock';

const mock = sinon.spy();
const sut = rewiremock.proxy<any>(
  './path/to/sut.ts',
  {
    './dependency': { mock }
  }
);

sut.func();

sinon.assert.calledOnce(mock);

Thank you for the quick response and clarification, noted.