DEV Community

Discussion on: Mocking ES6 class methods with Jest!

Collapse
 
cannikin profile image
Rob Cameron

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. :(

Collapse
 
jackcaldwell profile image
Jack Caldwell

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.

Collapse
 
09wattry profile image
Ryan

I have tried all of these functions and still the value is either the same or undefined. Any hints?

Thread Thread
 
mattarau profile image
Matt Arau

Have you tried afterEach(() => jest.resetAllMocks()); ?