I have a simple suite of tests where in some cases I want to mock a module and in some cases not. However, jest.mock()
works only if it's placed outside tests. Anyone has an idea why is that and what I'm doing wrong?
This is the actual import of a function I want to mock
import {hasSupport, getCallingCode} from 'utils/countryCallingCode';
And this is the mock of this function:
jest.mock('utils/countryCallingCode', () => ({
getCallingCode: () => '1',
hasSupport: () => true,
}));
Now, the working scenario is:
//imports
//mock
describe('...', () -> {
it('...', () -> {
});
});
This DOESN'T work:
//imports
describe('...', () -> {
//mock
it('...', () -> {
});
});
This also DOESN'T work:
//imports
describe('...', () -> {
it('...', () -> {
//mock
});
});