-
-
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]: resetAllMocks restoring mocks instead of resetting them #13808
Comments
Are you working on this? |
No, I don't know enough about Jest internals to suggest a fix.
|
This line in this PR introduced the regression; https://github.com/facebook/jest/pull/13692/files#diff-7ae0bd704c3c2789b19abe2bbf94aca3505e2a6b3823d85c7f6b316b216d37c9R1411 Looking here (https://github.com/facebook/jest/pull/13692/files#diff-7ae0bd704c3c2789b19abe2bbf94aca3505e2a6b3823d85c7f6b316b216d37c9L1409), the same function is called to restore the mocks. While it's called reset in the lambda function of the new addition, it's still the same function being called. Unsure if just removing this call is the solution, or if something else needs to be done to still retain functionality of that PR I'm actually a bit confused, as it seems the point of that PR (and the issue it fixes) is to make the behaviour of mockReset similar to mockRestore? AFAICT it's still a regression on resetAllMocks though, as that's actually removing the mock status of the function. But the original purpose of that PR is still a breaking change either way |
@feliperli Could you take a look, please? Seems like your PR (#13692) introduced this issue. Or is that expected behaviour? |
By the way, Jest is just another open source project maintained by few volunteers. See https://jestjs.io/blog/2022/05/11/jest-joins-openjs |
TIL, thanks for pointing that out. I did end up doing some digging, and while I'm not any closer to finding the root cause, I did notice this:
It seems that both of those methods end up calling all the I'm not sure if this is intentional, or if it's not, what a fix would look like, but hopefully this info at least helps. |
also seeing this impact our unit tests, with only a regenerated lockfile causing the breaking change |
Oh no :( I'm looking into it. |
I also see this!!!! |
I have a different problem, but I think the cause is the same change in describe('test console.log', () => {
console.log = jest.fn();
const log = jest.spyOn(console, 'log');
afterEach(() => {
log.mockReset();
});
test('console.log a', () => {
console.log('test a');
expect(log).toBeCalledWith('test a');
});
test('console.log b', () => {
/**
* An error is thrown on the next line:
* RangeError: Maximum call stack size exceeded
* at WeakMap.get (<anonymous>)
* at ModuleMocker._ensureMockState (node_modules/jest-mock/build/index.js:275:33)
*/
console.log('test b');
expect(log).toBeCalledWith('test b');
});
}); When I remove the line |
Seems related: I'm also getting random RangeError: Maximum Call Stack Size Exceeded that are pointing to the |
Should be fixed in #13866 |
Looks like the bug wasn't fixed in I've created a new issue at #13916 |
29.4.3 fixes the original issue for me, along with the "Maximum Call Stack Size Exceeded" error. Thanks all! |
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.0
Steps to reproduce
Simple test to reproduce:
Expected behavior
The test should pass
Actual behavior
The test fails with
Matcher error: received value must be a mock or spy function
.Additional context
It seems that
resetAllMocks
is acting likemockRestore
instead ofmockReset
.If I replace
jest.resetAllMocks()
withfooSpy.mockReset()
, the test passes as expected, whereas if I replace it withfooSpy.mockRestore()
it fails with that error again.Environment
The text was updated successfully, but these errors were encountered: