Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"jest.resetAllMocks();" does not work #83

Closed
Oliboy50 opened this issue Aug 22, 2018 · 6 comments
Closed

"jest.resetAllMocks();" does not work #83

Oliboy50 opened this issue Aug 22, 2018 · 6 comments

Comments

@Oliboy50
Copy link

Oliboy50 commented Aug 22, 2018

capture d ecran 2018-08-22 a 16 28 23

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

@clarkbw
Copy link
Owner

clarkbw commented Aug 30, 2018

Can you link to the code you're using? I don't have enough context from this to understand the problem.

@clarkbw clarkbw closed this as completed Oct 23, 2018
@Oliboy50
Copy link
Author

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

@clarkbw clarkbw reopened this Oct 23, 2018
@clarkbw
Copy link
Owner

clarkbw commented Oct 23, 2018

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.

@daniellizik
Copy link

daniellizik commented Oct 30, 2018

I had this same issue as well but as per this line I guess .clearAllMocks() is the correct method to use (reference)

I switched to clearAllMocks and now __STORAGE__ seems to be working.

@daniula
Copy link

daniula commented Feb 1, 2019

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.

@AOEChamp
Copy link
Contributor

AOEChamp commented Mar 5, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants