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

Automatic restore for spyOn #2972

Closed
jardakotesovec opened this issue Feb 22, 2017 · 9 comments
Closed

Automatic restore for spyOn #2972

jardakotesovec opened this issue Feb 22, 2017 · 9 comments

Comments

@jardakotesovec
Copy link

As already mentioned in #1749, could spyOn have automatic restore as jasmine has?

It would help to isolate spies for given test, as its simple to forget to call the restore at the end of the test (and can affect the other tests which is always difficult to track down).

And also there is no guarantee that the restore will get called, because test might fail in some expect, which stops the execution of the test and prevents calling the restore, which is usually called at the end of the test function.

@jardakotesovec jardakotesovec changed the title automatic restore for spyOn Automatic restore for spyOn Feb 22, 2017
@thymikee
Copy link
Collaborator

Similar issue was discussed here: #2965.

@jackfranklin
Copy link
Contributor

Would you also accept a PR to the docs to clear up the difference between clear/reset mocks? We've got very confused between clearMocks and resetMocks. My understanding is:

  • clearMocks resets all the mock's history but leaves the fake implementation
  • resetMocks resets any fake implementations but doesn't restore the original behaviour

Is that correct? If that is correct, it feels like restoreMocks as a way to put back the original implementation would fit nicely as a 3rd option. If not I'd love to see an example of how you do this at Facebook to avoid this being an issue :)

@thymikee
Copy link
Collaborator

@jackfranklin docs PRs are always welcome!

@jackfranklin
Copy link
Contributor

@thymikee OK, I'll get one in ;) Are my definitions of clear/reset mocks correct in the comment above?

@thymikee
Copy link
Collaborator

I don't like the naming either. The definitions seems ok 👍

@jackfranklin
Copy link
Contributor

@thymikee given we have mockFn.mockRestore(), would you be open to a PR that adds restoreMocks: true as a config that would call restoreAllMocks which in turn would call mockRestore on each known mock?

@thymikee
Copy link
Collaborator

Feel free to open a separate issue just for that, so we can discuss.

@geoffreyyip
Copy link

Looks like this feature's been in the codebase since #3580 was merged last year. May be worth closing.

@rickhanlonii
Copy link
Member

@geoffreyyip yup, thanks, docs are here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants