-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: jest.restoreAllMocks(); breaks global mock #13969
Comments
Instead of using describe('Describe', () => {
it('test1', () => {
const client = someLib.getClient();
await client.getConfigurationItems();
expect(someLib.getClient).toHaveBeenCalled(); // Passed for the first time
someLib.getClient.mockRestore();
client.getConfigurationItems.mockRestore();
});
it('test2', () => {
const client = someLib.getClient();
await client.getConfigurationItems();
expect(someLib.getClient).toHaveBeenCalled(); // Failed
someLib.getClient.mockRestore();
client.getConfigurationItems.mockRestore();
});
}); If any of the tests will run alone, it will pass; otherwise second test fails. This is because |
I know, but what if I have a tons of mocks? I assume it is not very convenient to do such manipulations every time. |
Sorry if that was not clear. I was trying to say that: afterEach(() => {
jest.restoreAllMocks();
}); Is equivalent to what I was showing in the above example. The idea is that the above example will fail on Jest 28, just like |
@mrazauskas Thank you, it works. Now need to refactor all the code and replace |
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. |
Version
29.4.3
Steps to reproduce
Expected behavior
I expect to see passed tests as expected. It works for jest 28v
Actual behavior
See error
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: