Does jest automatically restore mocked modules between test files? For example, if I call jest.mock('some_module')
in one file, do I need to ensure I call jest.unmock('some_module')
after all the tests are run in that file?
It's not clear to me whether that happens in the documentation.
You don't have to reset the mocks, as the test are run in parallel, every test file run in its own sandboxed thread. Even mocking JavaScript globals like Date
or Math.random
only affects the actual test file.
The only problem we had so far was mocking process.env.NODE_ENV
which affected other test that run at the same time. But reseting this after the test run solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With