-
-
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
Add restoreMocks
config option
#3580
Add restoreMocks
config option
#3580
Comments
Closing in favor of the PR. |
@cpojer There is currently no config like |
@tothandras I would suggest you to check this out https://github.com/JoinColony/jest-sandbox |
Thanks @sergeysolovev! I've used that once, but the experience is not the same as mocha+sinon. 😞 With mocha beforeEach, afterEach could be used to set up a sandbox ( |
@tothandras I agree, these frameworks have quite rich and sophisticated API, letting you do whatever you would like to. That' why I've started using jest together with sinon first. Later I found out, that I could manage everything only using jest. It's not that impossible, actually. The method jest.spyOn is really helpful for me. Here is an example on how I handle missing restoreMocks: https://github.com/sergeysolovev/swader/blob/master/src/containers/Resource.test.js Maybe it's not that pretty, but it's not that ugly actually. I wish it could give you some fresh ideas. |
@tothandras Oh yes, I forgot to mention, that big players like airbnb and paypal (not sure about the latter though) are switching to jest not for no reason :) The performance really worth it |
Any news on getting a config option for |
PR welcome :) Reopening as the original request was both the programmatic api and config, only the api was added. |
Taking a shot at this :) |
I basically did what was there already for clearMocks & resetMocks config options. Branch in my fork is here: https://github.com/gricard/jest/tree/gricard-restoremocks Re-reading docs. Still working on getting the integration tests to pass. |
@SimenB Oh, right. I had read that too. Thanks! |
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. |
Do you want to request a feature or report a bug?
Feature :)
What is the current behavior?
As discussed in #2972 (comment), currently Jest offers:
clearMocks
: clear any mocked calls but leave the mock implementationresetMocks
: remove fake impl but don't restore the originalThese align to the
jest.clearAllMocks
andjest.resetAllMocks
functions that in turn callmockFn.mockClear()
andmockFn.mockReset
.There is also
mockFn.mockRestore
which clears out the fake implementations and restores the original. This is the behaviour that we'd like to have for all mocks that's automatically run between each test.Therefore I'd like to propose a new function
jest.restoreAllMocks
which will callmockRestore
on each mock. In addition I'd like to add a config optionrestoreMocks: false
(by default) that will do this automatically.This would also mean
jest.spyOn
withrestoreMocks: true
would be very close to Jasmine'sspyOn
behaviour.The text was updated successfully, but these errors were encountered: