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 implementation
resetMocks: remove fake impl but don't restore the original
These align to the jest.clearAllMocks and jest.resetAllMocks functions that in turn call mockFn.mockClear() and mockFn.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 call mockRestore on each mock. In addition I'd like to add a config option restoreMocks: false (by default) that will do this automatically.
This would also mean jest.spyOn with restoreMocks: true would be very close to Jasmine's spyOn behaviour.
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.clearAllMocksandjest.resetAllMocksfunctions that in turn callmockFn.mockClear()andmockFn.mockReset.There is also
mockFn.mockRestorewhich 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.restoreAllMockswhich will callmockRestoreon 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.spyOnwithrestoreMocks: truewould be very close to Jasmine'sspyOnbehaviour.