I searched for a very long time how to mock any module with jest (like rewire does). I finally manage to do it this way, and it work like a charm :
jest.mock('common/js/browser-utils', () => ({
openBrowser: jest.fn()
}));
const { openBrowser: openBrowserSpy } = jest.requireMock(
'common/js/browser-utils'
);
But i wonder if there is another fast way to do so ?
I saw the genMockFromModule
method but i never makes it work (maybe it's not for that usage.)
What i want is simple : mocking a module by a jest.fn()
(or any auto mechanism), then being able to access this jest.fn() in my tests (here: openBrowserSpy
) to expect(assertions)
on it