Assume we have 2 async modules in a file module.js which I test them in module.test.js. I’ve imported them as:
import { fn1, fn2 } from './module';
and tested fn1 on a dedicated describe block, No issues there.
f2 uses f1 internally. I want to mock f1 to test f2 when it fails and succeeds.
Unfortunately it doesn’t work cause if I mock it as:
jest.mock('./module', () => ({
f1: jest.fn(),
}));
then the other tests fail:
TypeError: (0 , _module.fn1) is not a function
All samples in Jest docs deal with a single function imported, in my case there are more than one, and mocking the file as done above, affects all of them.
Any idea how to mock fn1 only for the describe block that tests fn2?