donavon/use-persisted-state

How to clear storage in jest tests?

danbruegge opened this issue ยท 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?

bmds commented

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();
});