"jest.resetAllMocks();" does not work
Oliboy50 opened this issue · comments
in the README, you say that jest.resetAllMocks
works, but it does not, if I use it, the __STORE__
is always empty even if I setItem()
in my tests
localStorage.clear();
for instance works as expected
but when I use jest.resetAllMocks
(to clear other mocks of my test) in combination to localStorage.clear();
, it does not work anymore
I'm running jest
v23.4.2
Can you link to the code you're using? I don't have enough context from this to understand the problem.
for instance, you could add a test in this project and try to use jest.resetAllMocks
yourself to check if it really does work
if I use it, the STORE is always empty even if I setItem() in my tests
you could add a test in this project and try to use
jest.resetAllMocks
yourself to check if it really does work
I'll try to take a look. Feel free to create a PR that fails this way.
jest.resetAllMocks
clears jest.fn()
mocked implementations. Because of that all jest.fn()
used in localstorage.js
will start returning undefined
. This is especially annoying if you enable resetMocks
in jest config.
I was hoping that adding beforeEach(() => require('jest-localstorage-mock')
would solve this issue but that's not a case.
Thanks @daniellizik that worked for me.
More specifically, resetAllMocks
breaks the mocks. clearAllMocks
clears the mocks (call count, etc) but does not clear the storage. I had to use it in conjunction with localStorage.clear()
to fully reset the state between tests.
I'm surprised this has been open for years now, when all that needs to be done is to update the documentation.