question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"jest.resetAllMocks();" does not work

See original GitHub issue
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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
daniellizikcommented, 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.

1reaction
AOEChampcommented, 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found