I have the following scenario:
const doSomething = () => {
const test = 1;
doAnotherThing();
return test + 1;
};
const doAnotherThing = () => {};
module.exports = {
doSomething,
doAnotherThing
};
And here is my test:
const MyModule = require('./myModule');
describe('MyModule', () => {
it('Should be able to spy another call', () => {
const spy = jest.spyOn(MyModule, 'doAnotherThing');
MyModule.doSomething();
expect(spy).toHaveBeenCalledTimes(1);
});
});
Question, is there a way for the call doAnotherThing() inside the doSomething() be spied by jest in some way, without using solutions like rewire?