DEV Community


Discussion on: Mocking ES6 class methods with Jest!

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

jackcaldwell profile image
Jack Caldwell Author

Looking at the mock function documentation -, you should be able to use mockFn.mockClear(), mockFn.mockReset(), or mockFn.mockRestore() depending on your needs. Hopefully this does what you need.

09wattry profile image

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()); ?

Forem Open with the Forem app