I have a Jest test file like the following:
// utils.test.js
let utils = require('./utils')
jest.mock('./utils')
test('print items', () => {
utils.printItems(['a'])
expect(utils.getImage).toHaveBeenLastCalledWith('a.png')
})
test('get image', () => {
utils = require.requireActual('./utils')
// `utils` is still mocked here for some reason.
expect(utils.getImage('note.png')).toBe('note')
})
And a mock like this:
// __mocks__/utils.js
const utils = require.requireActual('../utils');
utils.getImage = jest.fn(() => 'abc');
module.exports = utils;
Yet as you can see in my comment in the second test, utils is still the mocked version rather than the actual version of the module. Why is that? How can I get it to be the actual version, rather than the mocked version?