-
-
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
Set resetMocks to true by default #9047
Comments
This enforces independent tests. K Dodds likes this: facebook/create-react-app#9935 (comment) And it seems to be be becoming the norm: jestjs/jest#9047
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
Note the proposal does not match the example. clearAllMocks clears calls, instances, and results (and this is a good thing to do!): https://jestjs.io/docs/jest-object#jestclearallmocks resetAllMocks is what is called by setting Justification: clearing all mocks is great, because tests should be isolated (thanks @kentcdodds). Resetting all mocks is generally bad, because you will make manual mocks useless (also see #10419), and make useless any other mock implementation that a developer may have created for a test suite (solution to the latter is to re-implement it in a beforeEach, but there shouldn't be a need to do this) I would propose to close this ticket, and keep |
Is there any viable solution to restore manual mocks? Having reset on a beforeEach makes them look like they could be only used once. Looks like with this reset clearing the manual we have no use for manual mocks that can have a different implementation |
@bozdoz @drFabio It makes each mock remember it's initial implementation and provides a way to restore the initial implementation. I believe it would be a very viable solution to restoring manual mocks, and that it would be a safer and better way to reset the state between tests than resetAllMocks or restoreAllMocks. |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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. |
🚀 Feature Proposal
As described in the thread https://twitter.com/kentcdodds/status/1182744387190607872, we should set resetMocks param to true by default.
Motivation
In order to make our tests isolated.
Example
thanks to this new default value, we won't have to define afterAll method in our unit tests, in order to reset something.
Pitch
This feature is part of the core project . https://jestjs.io/docs/en/configuration#resetmocks-boolean. This change will make de developer experience smoother when writing unit test with jest.
As writing isolated test is a good practice, we should make it easy to implement, without writing extra code.
Why does this feature belong in the Jest core platform?
Common feature proposals that do not typically make it to core:
The text was updated successfully, but these errors were encountered: