Building websites/apps for almost 20 years. Full-stack, Ruby + Rails since 2006. Hobbiest woodworker, maker, husband and father of two. Callsign W6AKJ.
Any hints on how to restore the original functionality at the end of the test? When using this technique I'm seeing that the order the tests run in now matters—each test after this one ends up using that same mock. :(
Looking at the mock function documentation - jestjs.io/docs/en/mock-function-api, you should be able to use mockFn.mockClear(), mockFn.mockReset(), or mockFn.mockRestore() depending on your needs. Hopefully this does what you need.
Any hints on how to restore the original functionality at the end of the test? When using this technique I'm seeing that the order the tests run in now matters—each test after this one ends up using that same mock. :(
Looking at the mock function documentation - jestjs.io/docs/en/mock-function-api, you should be able to use
mockFn.mockClear()
,mockFn.mockReset()
, ormockFn.mockRestore()
depending on your needs. Hopefully this does what you need.I have tried all of these functions and still the value is either the same or undefined. Any hints?
Have you tried
afterEach(() => jest.resetAllMocks());
?