{"_id":"@brightinteractive/jest-localstorage-mock","_rev":"9-5b3e210b37a7b7f566447a181262ff12","name":"@brightinteractive/jest-localstorage-mock","dist-tags":{"latest":"1.4.1"},"versions":{"1.4.0":{"name":"@brightinteractive/jest-localstorage-mock","version":"1.4.0","author":{"url":"https://twitter.com/clarkbw","name":"Bryan Clark","email":"clarkbw@gmail.com"},"license":"ISC","_id":"@brightinteractive/jest-localstorage-mock@1.4.0","maintainers":[{"name":"richardhulm","email":"richard@bright-interactive.co.uk"}],"dist":{"shasum":"bf7d63da1bfff7876b2b630f9f3b0b9521291ebe","tarball":"https://registry.npmjs.org/@brightinteractive/jest-localstorage-mock/-/jest-localstorage-mock-1.4.0.tgz","integrity":"sha512-EtzN53XavmpQgtMNU88t5UzG5vhzwSw4+m5B3czfs0pF2LGtmMtkumwydbe02O1P09MjqM6hBUVMZP40ENEjRQ==","signatures":[{"sig":"MEUCIEDKKs6bZWswZvt4BV8aisEsNW5Yc4GcSg5MyMyKy8BaAiEAsbBcTRFBih0PtUSlEVG2FhGEvjqK2N1wtwzAHYqqgwU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"jest":{"bail":true,"setupFiles":["./__setups__/localstorage.js"],"collectCoverage":true,"coverageDirectory":"./coverage/"},"main":"dist/setup.js","module":"src/setup.js","gitHead":"e0f5b08be5cf15faf6289a7e411bd895fbe69941","private":false,"scripts":{"test":"jest","build":"rollup -c","version":"yarn run build","prettier":"prettier --single-quote --trailing-comma es5 --write \"{src,__{tests,setups}__}/**/*.js\" rollup.config.js","eslint-check":"eslint --print-config .eslintrc.js | eslint-config-prettier-check"},"_npmUser":{"name":"richardhulm","email":"richard@bright-interactive.co.uk"},"_npmVersion":"5.3.0","description":"Mock localstorage in your Jest tests","directories":{},"_nodeVersion":"8.2.1","devDependencies":{"jest":"^20.0.0","eslint":"^4.1.0","rollup":"^0.49.0","prettier":"^1.3.1","babel-jest":"^20.0.0","babel-preset-env":"^1.4.0","rollup-plugin-babel":"^3.0.0","eslint-config-prettier":"^2.0.0","eslint-plugin-prettier":"^2.0.1","rollup-plugin-node-resolve":"^3.0.0","babel-plugin-external-helpers":"^6.22.0"},"_npmOperationalInternal":{"tmp":"tmp/jest-localstorage-mock-1.4.0.tgz_1504518684729_0.03337104106321931","host":"s3://npm-registry-packages"}},"1.4.1":{"name":"@brightinteractive/jest-localstorage-mock","version":"1.4.1","author":{"url":"https://twitter.com/clarkbw","name":"Bryan Clark","email":"clarkbw@gmail.com"},"license":"ISC","_id":"@brightinteractive/jest-localstorage-mock@1.4.1","maintainers":[{"name":"angusjgoldsmith","email":"angus@dashery.co.uk"},{"name":"richardhulm","email":"richard@bright-interactive.co.uk"},{"name":"chrisdevereux","email":"devereux.chris@gmail.com"},{"name":"brightinteractive-admin","email":"ben@bright-interactive.co.uk"}],"dist":{"shasum":"470c1c8c7b88bc84e6a7608f8486586b31726bd2","tarball":"https://registry.npmjs.org/@brightinteractive/jest-localstorage-mock/-/jest-localstorage-mock-1.4.1.tgz","integrity":"sha512-uUOhaVkZtcqegAmCbFi6ltHNykTQXyd1p3N+Z2G3TN2qAzwfHj011QD2zG8UqiQe2N5uUoNjvJ2BGcfHDvY9Gg==","signatures":[{"sig":"MEUCIEQ5p62hbo+XjbUCVFtVVjjzj40N2qptJNTuvl0OcATrAiEA22Yl3DPCRRoIUihZl/RN04VnYcVs/v4xQKP4QxU7Ybg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"jest":{"bail":true,"setupFiles":["./__setups__/localstorage.js"],"collectCoverage":true,"coverageDirectory":"./coverage/"},"main":"dist/setup.js","module":"src/setup.js","gitHead":"e0f5b08be5cf15faf6289a7e411bd895fbe69941","private":false,"scripts":{"test":"jest","build":"rollup -c","version":"yarn run build","prettier":"prettier --single-quote --trailing-comma es5 --write \"{src,__{tests,setups}__}/**/*.js\" rollup.config.js","eslint-check":"eslint --print-config .eslintrc.js | eslint-config-prettier-check"},"_npmUser":{"name":"richardhulm","email":"richard@bright-interactive.co.uk"},"_npmVersion":"5.3.0","description":"Mock localstorage in your Jest tests","directories":{},"_nodeVersion":"8.2.1","devDependencies":{"jest":"^20.0.0","eslint":"^4.1.0","rollup":"^0.49.0","prettier":"^1.3.1","babel-jest":"^20.0.0","babel-preset-env":"^1.4.0","rollup-plugin-babel":"^3.0.0","eslint-config-prettier":"^2.0.0","eslint-plugin-prettier":"^2.0.1","rollup-plugin-node-resolve":"^3.0.0","babel-plugin-external-helpers":"^6.22.0"},"_npmOperationalInternal":{"tmp":"tmp/jest-localstorage-mock-1.4.1.tgz_1504519681254_0.29142342368140817","host":"s3://npm-registry-packages"}}},"time":{"created":"2017-09-04T09:51:25.704Z","modified":"2026-02-11T15:32:41.226Z","1.4.0":"2017-09-04T09:51:25.704Z","1.4.1":"2017-09-04T10:08:02.254Z"},"author":{"url":"https://twitter.com/clarkbw","name":"Bryan Clark","email":"clarkbw@gmail.com"},"license":"ISC","description":"Mock localstorage in your Jest tests","maintainers":[{"email":"developers@dash.app","name":"developers-dash"}],"readme":"\nUse this module with [Jest](https://facebook.github.io/jest/) to run web tests that rely on `localstorage` where you want a working localStorage like API and mocked localStorage functions.\n\nThis module has no runtime dependencies so your project won't pull in additional module dependencies by using this.\n\n[![npm](https://img.shields.io/npm/v/jest-localstorage-mock.svg)](https://www.npmjs.com/package/jest-localstorage-mock) [![npm](https://img.shields.io/npm/l/jest-localstorage-mock.svg)](https://github.com/clarkbw/jest-localstorage-mock/blob/master/LICENSE) [![Codecov](https://img.shields.io/codecov/c/github/clarkbw/jest-localstorage-mock.svg)](https://codecov.io/gh/clarkbw/jest-localstorage-mock) [![Greenkeeper badge](https://badges.greenkeeper.io/clarkbw/jest-localstorage-mock.svg)](https://greenkeeper.io/) [![Twitter](https://img.shields.io/twitter/url/https/github.com/clarkbw/jest-localstorage-mock.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)\n\n## Install\n\nThis should only be required as a dev dependency when your tests are running.\n\nyarn:\n\n```bash\nyarn add --dev jest-localstorage-mock\n```\n\nnpm:\n\n```bash\nnpm i --save-dev jest-localstorage-mock\n```\n\n## Setup\n\n### Module\n\nIn your `package.json` under the `jest` section add the module name to the `setupFiles` array. This is by far the simplest method for using this.\n\n```json\n\"jest\": {\n  \"setupFiles\": [\n    \"jest-localstorage-mock\"\n  ]\n}\n```\n\nYou can also append this to the array if you have other setup files.\n\n```json\n\"jest\": {\n  \"setupFiles\": [\n    \"./__setups__/other.js\",\n    \"jest-localstorage-mock\"\n  ]\n}\n```\n\n### Setup file\n\nAlternatively you can create a new setup file which then requires this module or add the `require` statement to an existing setup file.\n\n`__setups__/localstorage.js`\n```js\nrequire('jest-localstorage-mock');\n```\n\nAdd that file to your `setupFiles` array:\n\n```json\n\"jest\": {\n  \"setupFiles\": [\n    \"./__setups__/localstorage.js\"\n  ]\n}\n```\n\n### In create-react-app\n\nFor a [create-react-app](https://github.com/facebookincubator/create-react-app) project you can replace the [suggested mock](https://github.com/facebookincubator/create-react-app/tree/master/packages/react-scripts/template#srcsetuptestsjs) with this at the beginning of the existing `src/setupTests.js` file:\n\n```js\nrequire(\"jest-localstorage-mock\");\n```\n\n## In tests\n\nBy including this in your Jest setup you'll allow tests that expect a `localStorage` object to continue to run.  The module can also allow you to use the mocks provided to check that your localStorage is being used as expected.\n\nThe `__STORE__` attribute of `localStorage.__STORE__` is made available for you to directly access the localStorage object if needed.\n\n### Test Examples\n\nCheck that your `localStorage` calls were made when they were supposed to.\n\n```js\ntest('should save to localStorage', () => {\n  const KEY = 'foo', VALUE = 'bar';\n  dispatch(action.update(KEY, VALUE));\n  expect(localStorage.setItem).toHaveBeenLastCalledWith(KEY, VALUE);\n  expect(localStorage.__STORE__[KEY]).toBe(VALUE);\n  expect(Object.keys(localStorage.__STORE__).length).toBe(1);\n});\n```\n\nCheck that your storage is empty.\n\n```js\ntest('should have cleared the localStorage', () => {\n  dispatch(action.reset());\n  expect(localStorage.clear).toHaveBeenCalledTimes(1);\n  expect(localStorage.__STORE__).toEqual({}); // check store values\n  expect(localStorage.length).toBe(0); // or check length\n});\n```\n\nCheck that localStorage calls were not made when they shouldn't have been.\n\n```js\ntest('should not have saved to localStorage', () => {\n  const KEY = 'foo', VALUE = 'bar';\n  dispatch(action.notIdempotent(KEY, VALUE));\n  expect(localStorage.setItem).not.toHaveBeenLastCalledWith(KEY, VALUE);\n  expect(Object.keys(localStorage.__STORE__).length).toBe(0);\n});\n```\n\n## Development\n\n```\nyarn install\nyarn test\n```\n\n## Pull Request\n\nBefore every PR run the following:\n\n```\nyarn run prettier\n```\n\n## Publish\n\nWhen publishing a new build, run the following:\n\n```\nyarn run prettier\nyarn run build\nnpm version `${version}`\nnpm publish\ngit push --tags\n```\n","readmeFilename":"README.md"}