@sammyeby/jest-webstorage-mock
v1.0.4
Published
if using create react app, just import the script in setupTests.ts
Downloads
3
Maintainers
Readme
Jest-Webstorage-mock
if using create react app, just import the script in setupTests.ts
import "@sammyeby/jest-webstorage-mock"
then in your tests suites for example:
jest.spyOn(localStorage, 'setItem')
jest.spyOn(sessionStorage, 'setItem')
Or if you have your own test setup file or created your own mock file for example: myMock.ts
,
you can just import it in your myMock.ts
file
//__jest__/myMock.ts
import "@sammyeby/jest-webstorage-mock"
//...other mocks here...
and then in package.json add below
"jest": {
"setupFiles": [
"<rootDir>/__jest__/myMock.ts"],