{"_id":"mock-react-redux","_rev":"5-4d3bec77da79b3c6da619735480ac8c8","name":"mock-react-redux","dist-tags":{"latest":"0.4.0"},"versions":{"0.2.2":{"name":"mock-react-redux","version":"0.2.2","keywords":["mock","redux","jest","tests","spies","dispatch","selectors","hooks"],"author":{"name":"Codecademy"},"license":"MIT","_id":"mock-react-redux@0.2.2","maintainers":[{"name":"codecademy","email":"dev@codecademy.com"}],"homepage":"https://github.com/Codecademy/mock-react-redux#readme","bugs":{"url":"https://github.com/Codecademy/mock-react-redux/issues"},"dist":{"shasum":"e719f6d46ba69e88cd15e8bcd2acadc660d28f6c","tarball":"https://registry.npmjs.org/mock-react-redux/-/mock-react-redux-0.2.2.tgz","fileCount":36,"integrity":"sha512-26LfIkvmAaPR7F9uOzsvbLIf2gCJ2fBhqGQWE//a0wRat2rWQ9RSO8a5ZuazQuHC6HjSErd5k0yUhPoM3V3QRg==","signatures":[{"sig":"MEYCIQDLa11YAWJKG5hQSLYxdMJw6Z2MnaLvF5h5DwRutlm8egIhAJ76ZfHUs7XvMg3I6tSekh9OsSqt5DLJkLn+hFWcMhgM","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":43969,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJezaXVCRA9TVsSAnZWagAAEP8P/jaTQvrLOQw+xFDU06mZ\nd0u1VX4GoLMDy3Ozh+8qeeJWogwHPpsbh2lJ3/pSpuZx0ljRJ8ND2nEEL2MX\nUwWX6vSxmb85byucBP+wPzrV8T6xWMEc8HJ1H3lzVj8ltDUXp579ebtJg27k\nvP7IXKLd5u407S5rr4MNgXUfZvPLTtw3dtnoBkxLgHIoGnB5cvmMma4GxJun\nG9ilGvsyBzk3JUVFORiLgqh3FMPp0NRE9GiN0Bzc0BFIVNoD4TaDT4bMDO9S\nfLxn/JuIb/+H7VCeYZ6DgQ/l9+bn6Txo9gQ20sh7HGXiQVeTSwtc4W2fyxcb\nG2gG7VisjVRnxjdKuhVzIPz0yFPgYFqsPmCRjRSOx1wDTBMTrb8ElAVEkG4u\nwM3cNbOIIO+TAYnYPfDvq6PBlHlqfCEmU37bsMrWThefA5txFs42GQEcX/2Y\nBjJlc3NGZxOzyBAgX68SFH1w7WRjwg/ttSBjQkzHFt1QIFqqOKHual83rIy0\n3ODG/yyYYYnfDy8wgwLsJIr2MCeFfeMarTiOrmmCFqaSGLTcUn8cyCe6Wo3v\nCLKZGF/TE1XBTpINBDcq3mU1jmymkpVr7iEEF42sImjLgrQmSPB/aDTHIcIQ\nZ7rSmY83t35jL2EEmhPvl7xRz3BA3FHjoMjwU9xOlutqpdyvnO4a8mmCVpI5\nohHt\r\n=uCyB\r\n-----END PGP SIGNATURE-----\r\n"},"main":"src/index.js","husky":{"hooks":{"pre-commit":"lint-staged"}},"types":"src/index.d.ts","gitHead":"307859ec94d9c7df327cbb4688acdc17b39941ef","scripts":{"tsc":"tsc","test":"jest","eslint":"eslint \"./src/*.ts\" \"./src/**/*.ts\" --report-unused-disable-directives","test:ci":"jest --maxWorkers=2","prettier":"prettier \"./*.{json,ts,yaml}\" \"./src/**/*.{json,ts,yaml}\"","prettier:write":"npm run prettier -- --write"},"_npmUser":{"name":"codecademy","email":"dev@codecademy.com"},"repository":{"url":"git+https://github.com/Codecademy/mock-react-redux.git","type":"git"},"_npmVersion":"6.14.5","description":"Mocks out Redux actions and selectors for clean React Jest tests.","directories":{},"lint-staged":{"**/*.{js,json,ts,xml,yaml}":["prettier --write"]},"_nodeVersion":"14.3.0","dependencies":{"@types/react":"^16.9.35","lodash.mapvalues":"^4.6.0","@types/react-redux":"^7.1.9"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.0.1","husky":"^4.2.5","react":"^16.13.1","eslint":"^7.1.0","prettier":"^2.0.5","react-dom":"^16.13.1","babel-jest":"^26.0.1","typescript":"^3.9.3","@types/jest":"^25.2.3","lint-staged":"^10.2.6","react-redux":"^7.2.0","@babel/preset-env":"^7.9.6","@babel/preset-react":"^7.9.4","@testing-library/react":"^10.0.4","eslint-config-prettier":"^6.11.0","@types/lodash.mapvalues":"^4.6.6","@types/redux-mock-store":"^1.0.2","@babel/preset-typescript":"^7.9.0","@typescript-eslint/parser":"^3.0.0","@types/testing-library__react":"^10.0.1","@typescript-eslint/eslint-plugin":"3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mock-react-redux_0.2.2_1590535636530_0.18812986863191417","host":"s3://npm-registry-packages"}},"0.3.0":{"name":"mock-react-redux","version":"0.3.0","keywords":["mock","redux","jest","tests","spies","dispatch","selectors","hooks"],"author":{"name":"Codecademy"},"license":"MIT","_id":"mock-react-redux@0.3.0","maintainers":[{"name":"codecademy","email":"dev@codecademy.com"}],"homepage":"https://github.com/Codecademy/mock-react-redux#readme","bugs":{"url":"https://github.com/Codecademy/mock-react-redux/issues"},"dist":{"shasum":"25bf7a45818fc0acff9469e79f3db68cba1521ab","tarball":"https://registry.npmjs.org/mock-react-redux/-/mock-react-redux-0.3.0.tgz","fileCount":36,"integrity":"sha512-yCQi/x0h3q8EnAcsh7P3b3Ex8RfAXoKZqYXv6NaCCIr4bUIxNQmsbwurzJHSgsvinfS129qfqHexteLmOwHIPw==","signatures":[{"sig":"MEYCIQCacHR8ZSKk+0ehk6Xc3NeWw+HlOy+jQle6miCBePRz3AIhALjEoQwbK7ny459cCEzJT1EvEo8pbx6wI2n82JnTeSQG","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":50905,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe1ofSCRA9TVsSAnZWagAA4NEP/3MGvtJ9iJSXhWuBKWk4\nqkk2nzeyB3kU05w+oaqDXQFs9vViw+gNTRBJj72GSc/pNVdh8ISIlpW9kQyn\n4nxxWo993UvmyHB25mIaEJw4Eo98AL8oE+cjoLFEx41F0jw6G1zMkLlMYTrQ\nDofOrAP+xzMGeAoGmTNu4YqhOry5F2ZdnxLbO/ccdr/jSEnBLa5AUhH4b2yP\nsgOKM79PzB6tjtwPCUJHzt5liMDdr4GuZyJjjigqxEQBaAQ92xUU7VX92p9B\nBLoKzv0OotuDovCKgvdo+HiqDcpKwk7w7isU4lv+kq7xorpjAyZXm2hr/ctG\nm/XaHi7b2Bdgh2Q0esIf4F8CoLHQkCcHwHl8ZInKN1R9mzqOggJuH9mdGuQM\nbQFelJkSsHFvQSh7To4As7x+kQgHj+tQ3sRuf6dVJvykZHPHgY0uXI/DqI9x\nFo69qR7733unWu/yCyhLtw+urvF8zs6D2BDnFB1NPcYfAzbKU6ODH3ETcM1M\nwK+9pwXjGL3Nx/nI0jZqqRPizXL3JefTcm3ps2ytELlPLXSDRza0zBbfqoRm\nbxo4BNwypz88KSxc0Q3Fy0o7ckIp09q1dYLxMxRp1p4hCeMYuFBzOlysFr7Q\nUusYk78AJ0j9sLNilBCAndBE0k5HdyYqfDeu5dFq/yO8i/222LjRrfaI9Cg0\nnqVl\r\n=vkDv\r\n-----END PGP SIGNATURE-----\r\n"},"main":"src/index.js","husky":{"hooks":{"pre-commit":"lint-staged"}},"types":"src/index.d.ts","gitHead":"3be57840c1e2702728cf7dde96c74c46ce312a35","scripts":{"tsc":"tsc --module commonjs","test":"jest","eslint":"eslint \"./src/*.ts\" \"./src/**/*.ts\" --report-unused-disable-directives","test:ci":"jest --maxWorkers=2","prettier":"prettier \"./*.{json,ts,yaml}\" \"./src/**/*.{json,ts,yaml}\"","prettier:write":"npm run prettier -- --write"},"_npmUser":{"name":"codecademy","email":"dev@codecademy.com"},"repository":{"url":"git+https://github.com/Codecademy/mock-react-redux.git","type":"git"},"_npmVersion":"6.14.5","description":"Mocks out Redux actions and selectors for clean React Jest tests.","directories":{},"lint-staged":{"**/*.{js,json,ts,xml,yaml}":["prettier --write"]},"_nodeVersion":"14.3.0","dependencies":{"@types/react":"^16.9.35","lodash.mapvalues":"^4.6.0","@types/react-redux":"^7.1.9"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.0.1","husky":"^4.2.5","react":"^16.13.1","eslint":"^7.1.0","prettier":"^2.0.5","react-dom":"^16.13.1","babel-jest":"^26.0.1","typescript":"^3.9.3","@types/jest":"^25.2.3","lint-staged":"^10.2.6","react-redux":"^7.2.0","@babel/preset-env":"^7.9.6","@babel/preset-react":"^7.9.4","@testing-library/react":"^10.0.4","eslint-config-prettier":"^6.11.0","@types/lodash.mapvalues":"^4.6.6","@types/redux-mock-store":"^1.0.2","@babel/preset-typescript":"^7.9.0","@typescript-eslint/parser":"^3.0.0","@types/testing-library__react":"^10.0.1","@typescript-eslint/eslint-plugin":"3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mock-react-redux_0.3.0_1591117777547_0.2598248597782624","host":"s3://npm-registry-packages"}},"0.4.0":{"name":"mock-react-redux","version":"0.4.0","keywords":["mock","redux","jest","tests","spies","dispatch","selectors","hooks"],"author":{"name":"Codecademy"},"license":"MIT","_id":"mock-react-redux@0.4.0","maintainers":[{"name":"codecademy","email":"dev@codecademy.com"}],"homepage":"https://github.com/Codecademy/mock-react-redux#readme","bugs":{"url":"https://github.com/Codecademy/mock-react-redux/issues"},"dist":{"shasum":"9166fd857ff2eac7580b269558b80c023ed2a181","tarball":"https://registry.npmjs.org/mock-react-redux/-/mock-react-redux-0.4.0.tgz","fileCount":36,"integrity":"sha512-InDFKfvwkOqwssntXxQ1XFtIuemBBYn1l1vdBJDRzUstvsUDuibfrcN0ZuLa0VWat7edBRrNdXriFJVt7ATHdQ==","signatures":[{"sig":"MEYCIQCQEfw2V3eftr9GKe0SijynI8GFBn/4t2SmZ6lmChZ+YgIhAMNSeiCQ5hbVrZkH21eJf5nJNGJefwswFBFalB+JYy8M","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":53039,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfg0XdCRA9TVsSAnZWagAAwn4QAJ8qkBnqT7ik+A/ySZDT\nA7grtdpk/FepjwTqMhQrlIyx/QgQ3jQHitJbybbHUOYQNs161feYony4XK9T\nXhzY12KVCmQF/MxDyR+xwko6MpEf49LyeENnBWPaT3ZxhXBlwmLaR+OCjATA\nO9EwH/6BmW4qeXlDWYuE+fZ1pONLEJp4qCv178/+fD4istG5FcOX7VeCn8YQ\nZfBrAx3PBgFRg0Dzzj6zJkJrUVKWP50D8kcN+gvXdpvBY/gSlPBiegq1CyGE\ndBrZHe/H4UDwSDB0oOHtUne/3+JRVqs3PNQZCZV+lVimdHxB3YWePHc+DeUN\n4tXuIJHgo1o+DGsU0m7NTn5r3dP96Wzwqr1RMsXh2l8xZiObPr+v2xCtlPek\nkOK18JeN3xmb0YUynCC3qWbv65v2cza8NvGJ49nXbfEfhBEumELOw4LiqScD\niIvqAh+bo5Vbu4qiKHYFZROMmGAOf13Zq/dbizNEJWOoQld2rNZKgPH+yp+b\nLBsmzJ0kbv18yvuNAojUFJojaBFXvCcuXQ0YMFmL6T75r2BLcj4NMV/dyMP6\nMolRCOjTZPZ7yjEiM1yd6TPBJKWRBOtem4zTEsHe60009ugLc7iJ15yjnl0T\nQwiTwNH94AaOUsR2el/sAI0xuA/DJ1xXNKt0blezhFzaRjBl8j7zJrwnVba6\nr4zC\r\n=0dbo\r\n-----END PGP SIGNATURE-----\r\n"},"main":"src/index.js","husky":{"hooks":{"pre-commit":"lint-staged"}},"types":"src/index.d.ts","gitHead":"7ff8a5c4f10ff13b116079906f8c088d3899fef8","scripts":{"tsc":"tsc --module commonjs","test":"jest","eslint":"eslint \"./src/*.ts\" \"./src/**/*.ts\" --report-unused-disable-directives","test:ci":"jest --maxWorkers=2","prettier":"prettier \"./*.{json,ts,yaml}\" \"./src/**/*.{json,ts,yaml}\"","prettier:write":"npm run prettier -- --write"},"_npmUser":{"name":"codecademy","email":"dev@codecademy.com"},"repository":{"url":"git+https://github.com/Codecademy/mock-react-redux.git","type":"git"},"_npmVersion":"6.14.8","description":"Mocks out Redux actions and selectors for clean React Jest tests.","directories":{},"lint-staged":{"**/*.{js,json,ts,xml,yaml}":["prettier --write"]},"_nodeVersion":"14.13.1","dependencies":{"@types/react":"^16.9.35","lodash.mapvalues":"^4.6.0","@types/react-redux":"^7.1.9"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.0.1","husky":"^4.2.5","react":"^16.13.1","eslint":"^7.1.0","prettier":"^2.0.5","react-dom":"^16.13.1","babel-jest":"^26.0.1","typescript":"^3.9.3","@types/jest":"^25.2.3","lint-staged":"^10.2.6","react-redux":"^7.2.0","@babel/preset-env":"^7.9.6","@babel/preset-react":"^7.9.4","@testing-library/react":"^10.0.4","eslint-config-prettier":"^6.11.0","@types/lodash.mapvalues":"^4.6.6","@types/redux-mock-store":"^1.0.2","@babel/preset-typescript":"^7.9.0","@typescript-eslint/parser":"^3.0.0","@types/testing-library__react":"^10.0.1","@typescript-eslint/eslint-plugin":"3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mock-react-redux_0.4.0_1602438621431_0.30414482978139734","host":"s3://npm-registry-packages"}}},"time":{"created":"2020-05-26T23:27:16.529Z","modified":"2025-12-09T21:51:19.969Z","0.2.2":"2020-05-26T23:27:16.692Z","0.3.0":"2020-06-02T17:09:37.654Z","0.4.0":"2020-10-11T17:50:21.602Z"},"bugs":{"url":"https://github.com/Codecademy/mock-react-redux/issues"},"author":{"name":"Codecademy"},"license":"MIT","homepage":"https://github.com/Codecademy/mock-react-redux#readme","keywords":["mock","redux","jest","tests","spies","dispatch","selectors","hooks"],"repository":{"url":"git+https://github.com/Codecademy/mock-react-redux.git","type":"git"},"description":"Mocks out Redux actions and selectors for clean React Jest tests.","maintainers":[{"email":"dev@codecademy.com","name":"codecademy-eng"}],"readme":"# 🎭 mock-react-redux\n\n[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)](https://prettier.io)\n![TypeScript: Strict](https://img.shields.io/badge/typescript-strict-brightgreen.svg)\n[![NPM version](https://badge.fury.io/js/mock-react-redux.svg)](http://badge.fury.io/js/mock-react-redux)\n[![Circle CI](https://img.shields.io/circleci/build/github/Codecademy/mock-react-redux.svg)](https://circleci.com/gh/Codecademy/mock-react-redux)\n[![Join the chat at https://gitter.im/Codecademy/mock-react-redux](https://badges.gitter.im/Codecademy/mock-react-redux.svg)](https://gitter.im/Codecademy/mock-react-redux?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nMocks out Redux actions and selectors for clean React Jest tests.\n\nTired of setting up, updating, and debugging through complex _Redux_ states in your _React_ tests?\nUse this package if you'd like your React component tests to not take dependencies on your full Redux store.\n\n> See [FAQs](./docs/FAQs.md) for more backing information. 📚\n\n## Usage\n\n```js\nimport { mockReactRedux } from \"mock-react-redux\";\n```\n\n`mock-react-redux` stubs out [`connect`](https://react-redux.js.org/api/connect) and the [two common Redux hooks](https://react-redux.js.org/api/hooks) used with React components.\nCall `mockReactRedux()` before your render/mount logic in each test.\n\n### Mocking State\n\n```tsx\nmockReactRedux().state({\n  title: \"Hooray!\",\n});\n```\n\nSets a root state to be passed to your component's selectors.\n\n```tsx\nit(\"displays the title when there is a title\", () => {\n  mockReactRedux().state({\n    title: \"Hooray!\",\n  });\n\n  // state => state.title\n  const view = render(<RendersTitle />);\n\n  view.getByText(\"Hooray!\");\n});\n```\n\nSee [Selectors](./docs/Selectors.md) for more documentation or [Heading](./docs/examples/Heading.test.tsx) for a code example.\n\n### Mocking Selectors\n\n```tsx\nmockReactRedux()\n  .give(simpleSelector, \"Hooray!\")\n  .giveMock(fancySelector, jest.fn().mockReturnValueOnce(\"Just the once.\"));\n```\n\nProvide results to the [`useSelector`](https://react-redux.js.org/api/hooks#useselector) function for individual selectors passed to it.\nThese work similarly to Jest mocks: `.give` takes in the return value that will always be passed to the selector.\n\n```tsx\nit(\"displays the title when there is a title\", () => {\n  mockReactRedux().give(selectTitle, \"Hooray!\");\n\n  // state => state.title\n  const view = render(<RendersTitle />);\n\n  view.getByText(\"Hooray!\");\n});\n```\n\nIf you'd like more control over the return values, you can use `.giveMock` to provide a [Jest mock](https://jestjs.io/docs/en/mock-functions.html).\n\nSee [Selectors](./docs/Selectors.md) for more documentation or [Heading](./docs/examples/Heading.test.tsx) for a code example.\n\n### Dispatch Spies\n\n```tsx\nconst { dispatch } = mockReactRedux();\n```\n\nThe `dispatch` function returned by [`useDispatch`](https://react-redux.js.org/api/hooks#usedispatch) will be replaced by a `jest.fn()` spy.\nYou can then assert against it as with any Jest mock in your tests:\n\n```tsx\nit(\"dispatches the pageLoaded action when rendered\", () => {\n  const { dispatch } = mockReactRedux();\n\n  // dispatch(pageLoaded())\n  render(<DispatchesPageLoaded />);\n\n  expect(dispatch).toHaveBeenCalledWith(pageLoaded());\n});\n```\n\nSee [Dispatches](./docs/Dispatches.md) for more documentation or [Clicker](./docs/examples/Clicker.test.tsx) for a code example.\n\n## Gotchas\n\n- The first `mock-react-redux` import _must_ come before the first `react-redux` import in your test files.\n- `.give` and `.giveMock` will only apply when selectors are passed directly to `useSelector` (e.g. `useSelector(selectValue)`).\n  - See [FAQs](./docs/FAQs.md#help-my-give-selectors-arent-getting-mocked) for more tips and tricks.\n\n### Hybrid Usage\n\nYou don't have to use `mock-react-redux` in _every_ test file in your repository.\nOnly the test files that import `mock-react-redux` will have `react-redux` stubbed out.\n\n### TypeScript Usage\n\n`mock-react-redux` is written in TypeScript and generally type safe.\n\n- `mockReactRedux()` has an optional `<State>` type which sets the type of the root state passed to `.state`.\n- `.give` return values must match the return types of their selectors.\n- `.giveMock` mocks must match the return types of their selectors.\n\n_Heck yes._ 🤘\n\n## Development\n\nRequires:\n\n- [Node.js](https://nodejs.org) >12\n- [Yarn](https://yarnpkg.com/en)\n\nAfter [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo):\n\n```\ngit clone https://github.com/<your-name-here>/mock-react-redux\ncd mock-react-redux\nyarn\n```\n\n### Contribution Guidelines\n\nWe'd love to have you contribute!\nCheck the [issue tracker](https://github.com/Codecademy/mock-react-redux/issues) for issues labeled [`accepting prs`](https://github.com/Codecademy/mock-react-redux/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22accepting+prs%22) to find bug fixes and feature requests the community can work on.\nIf this is your first time working with this code, the [`good first issue`](https://github.com/Codecademy/mock-react-redux/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+) label indicates good introductory issues.\n\nPlease note that this project is released with a [Contributor Covenant](https://www.contributor-covenant.org).\nBy participating in this project you agree to abide by its terms.\nSee [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md).\n","readmeFilename":"README.md"}