use-persisted-state
use-persisted-state copied to clipboard
How to clear storage in jest tests?
Hi,
i discovered that using window.localStorage.clear()
in beforeEach
has no effect in jest tests. Tried also global
instead of window
.
https://codesandbox.io/s/2o1ljwjwy0
All test should work because i only click once.
How can i reset the storage for each test?
Also running into this when using https://github.com/clarkbw/jest-localstorage-mock
As this shows up as second result on google search for "jest clear local storage", it works for me via:
beforeEach(() => {
window.localStorage.clear();
});