Hi,
I have a react component that uses functions from a module to fetch data and I want to mock it, so I used the jest.mock in order to so and it worked. But I've reached a point in my test where I want to override one of the functions in the mock module and I can't find a way to achieve it.
For example:
moduleName.js
export const a = () => 1;
export const b = () => 2;
__mocks__/moduleName.js
export const a = () => 3;
export const b = () => 4;
moduleName.test.js
jest.mock('moduleName);
describe('Test block', () => {
it('First test that uses the react component', () => {
some code that with mount the component.
here if the component will call the a function from the module it will receive the value 3(from the
mock).
})
it('Second test the uses the react component', () => {
here I want to override the a function to return the value 8 in the mock.
But if I mount the component it will still call the a function and will receive the value 3.
})
})
How can I achieve that? I tried jest.doMock but it doesnt override the jest.mock
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
just in case someone needs this in the future, you can use the second parameter in the jest.mock to do that.
https://jestjs.io/docs/en/jest-object#jestmockmodulename-factory-options