My component uses the external function that I want to mock just in one of my tests.
If I use
jest.mock('utils/deviceUtils', () => ({
getDeviceInfo: jest.fn(() => ({
isSupportedTouchDevice: true,
isAndroid: true,
isMobile: true,
}))
}))
mock works for every test (getDeviceInfo()
is not called in the test, only in component, if that's important).
If I use jest.doMock('utils/deviceUtils, /* ... */
in required test nothing is mocked.
beforeEach(() => {
jest.resetModules()
})
doesn't help.
You probably have modules required already, you need to re-require everything after calling jest.doMock.
jest.resetModules();
jest.doMock('MyModule');
require('MyModule');
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. Thank you :)
Most helpful comment
You probably have modules required already, you need to re-require everything after calling jest.doMock.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. Thank you :)