I have a mock module like this in my component test file
jest.mock(\'../../../magic/index\', () => ({
navigationEnabled: () => true,
guidance
I had a hard time getting the accepted answers to work - my equivalents of navigationEnabled
and guidanceEnabled
were undefined when I tried to call mockReturnValueOnce
on them.
Here's what I had to do:
In ../../../magic/__mocks__/index.js
:
export const navigationEnabled = jest.fn();
export const guidanceEnabled = jest.fn();
in my index.test.js
file:
jest.mock('../../../magic/index');
import { navigationEnabled, guidanceEnabled } from '../../../magic/index';
import { functionThatReturnsValueOfNavigationEnabled } from 'moduleToTest';
it('is able to mock', () => {
navigationEnabled.mockReturnValueOnce(true);
guidanceEnabled.mockReturnValueOnce(true);
expect(functionThatReturnsValueOfNavigationEnabled()).toBe(true);
});