"jest.resetAllMocks();" does not work
See original GitHub issuein 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Why is my resetAllMocks not working in jest
I was experiencing the same problem until I placed jest.resetAllMocks(); inside afterEach like so: afterEach(() => { jest.
Read more >How to automatically reset mocks and restore spies in Jest
When I used jest for the first time for unit testing, it struck me that function mocks and spies were not automatically reset...
Read more >The Jest Object
mockRestore() on every mocked function. Beware that jest.restoreAllMocks() only works when the mock was created with jest.spyOn ; other mocks ...
Read more >Jest mock and spy — mockClear vs mockReset vs mockRestore
Because the mock was not called we expect that the mock will be called 0 times. MOCK. Here we are mocking whole module...
Read more >jest.clearAllMocks vs jest.resetAllMocks vs ...
However, this also could lead to some problem if you don't clear it. ... jest.resetAllMocks. A superset of clearAllMocks() and it also reset ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.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 withlocalStorage.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.