use-persisted-state icon indicating copy to clipboard operation
use-persisted-state copied to clipboard

How to clear storage in jest tests?

Open danbruegge opened this issue 5 years ago • 2 comments

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?

danbruegge avatar Apr 05 '19 18:04 danbruegge

Also running into this when using https://github.com/clarkbw/jest-localstorage-mock

bmds avatar Jun 13 '19 14:06 bmds

As this shows up as second result on google search for "jest clear local storage", it works for me via:

beforeEach(() => {
    window.localStorage.clear();
});

enzoferey avatar Jul 23 '22 16:07 enzoferey