clarkbw / jest-localstorage-mock

A module to mock window.localStorage and window.sessionStorage in Jest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use it after update Jest

PengWang0316 opened this issue · comments

When I was using Jest 23.1.0, the library runs perfectly. After I update Jest to 23.4.2 and jest-environment-jsdom to 23.4.0, the test give me message:

SecurityError: localStorage is not available for opaque origins

I added

"testURL": "http://localhost" 
"verbose": true

to Jest configuration. But I still get the error message:

expect(jest.fn())[.not].toHaveBeenCalledTimes()
jest.fn() value must be a mock function or spy.

when I have test code like "expect(localStorage.removeItem).toHaveBeenCalledTimes(1);"

#80 addresses this.

Thank you for the answer. I actually find out the jsdom starts to support the localStorage. So, we can actually test the localStorage without mock.