For a particular test, I need the value of isBanana
to be false
.
It has been successful when I mocked the function in the main index.test.js
file. However, this caused issues with other tests that require isBanana
to be true
.
jest.mock("myapp-api-functions", () => {
console.log(`executing mock function`);
return {
...jest.requireActual("myapp-api-functions"),
isBanana: false,
};
});
When attempting to move the jest.mock()
inside the body of the test, the value of isBanana
reverts to true
and the test fails.
it(`should error when someone tries to use the mock account in production`, async () => {
jest.mock("myapp-api-functions", () => {
console.log(`executing mock function`);
return {
...jest.requireActual("myapp-api-functions"),
isBanana: false,
};
});
...same test function that previously passed...
});
The mocking approach does not seem to work for this specific scenario, resulting in test failure.
Is there a way to effectively mock the primitive value for just one test?