Skip to content
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

Add "restoreAllMocks" to the API. Closes #3580 #4045

Merged
merged 1 commit into from Jul 17, 2017
Merged

Add "restoreAllMocks" to the API. Closes #3580 #4045

merged 1 commit into from Jul 17, 2017

Conversation

mjesun
Copy link
Contributor

@mjesun mjesun commented Jul 17, 2017

Summary

A new .spyOn method was added in Jest 19.0 to allow spying on methods without skipping their original behavior. However, Jest lacked a method to clean all the spies at once, as opposed as other existing APIs for cleaning or resetting mocks. Further discussion can be found on #3580.

Now, all spies can be cleaned at once by calling jest.restoreAllMocks, which naming is consistent with other group resets.

Test plan

New tests were added, so running the whole suit of tests should be enough. This would also include running flow to check typing errors. If you can think about something else, let me know :)

Copy link
Contributor

@aaronabramov aaronabramov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code looks good, but i'm not sure about the API.
Even now, every time i see resetAllMocks or clearAllMocks i have to go to the documentation to see what is what. Now we have a third method with a similar name which will make it even more complicated.

Since it's only relevant to spies, maybe it should be called resetAllSpies? or something similar

@mjesun
Copy link
Contributor Author

mjesun commented Jul 17, 2017

I agree with the naming confusion. I never remember the differences between reset and clear. However, the method is named after the convention already followed; as @jackfranklin mentioned, right now we have the following APIs:

  • mockReset, which global equivalent is resetAllMocks, and
  • mockClear, which global equivalent is clearAllMocks.

Thus, the global equivalent of mockRestore should be restoreAllMocks, following the reordering convention used for the others.

@aaronabramov
Copy link
Contributor

yeah. i guess it's a bigger problem that we'll need to solve at some point :)
failing tests seem to be the ones that are broken in master. i'll merge this with red CI

@aaronabramov aaronabramov merged commit a5a8a13 into jestjs:master Jul 17, 2017
@mjesun mjesun deleted the restore-all-mocks branch July 18, 2017 13:33
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants