New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
jest.mock factory doesn't work inside a test #10494
Comments
Have you seen #764 and see if it can help you? |
@JeromeDeLeon Same problem with code from #764 |
because thread 2582 is closed, posting the temporary solution for others By using jest.mock and jest.spyOn, we can mock inside every test with different implementation
|
You cannot mock after the fact - you need to mock before importing. describe('TEST', () => {
it('node mock false', () => {
jest.resetModules();
jest.mock('detect-node', () => false);
const {myTestFn} = require('./fn');
myTestFn(); // will print constant
});
it('node mock true', async () => {
jest.resetModules();
jest.mock('detect-node', () => true);
const {myTestFn} = require('./fn');
myTestFn(); // will print constant
});
}); If |
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
馃悰 Bug Report
According to this thread: #2582 it doesn't work.
To Reproduce
Create test for
myTestFn
which return mocked value.Test file:
Fn file:
Expected behavior
Should print mocked value.
Expected behavior
It print current value (node=true)
envinfo
The text was updated successfully, but these errors were encountered: