{"id":13727483,"url":"https://github.com/akameco/reducer-tester","last_synced_at":"2025-05-15T02:31:32.728Z","repository":{"id":57350061,"uuid":"126597864","full_name":"akameco/reducer-tester","owner":"akameco","description":"Utilities for testing redux reducers","archived":false,"fork":false,"pushed_at":"2020-02-09T16:05:54.000Z","size":899,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T17:48:16.775Z","etag":null,"topics":["diff","jest","react","reducer","redux","snapshot","snapshot-testing","test"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akameco.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-24T12:39:36.000Z","updated_at":"2020-06-04T01:54:02.000Z","dependencies_parsed_at":"2022-09-16T02:12:26.920Z","dependency_job_id":null,"html_url":"https://github.com/akameco/reducer-tester","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Freducer-tester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Freducer-tester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Freducer-tester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akameco%2Freducer-tester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akameco","download_url":"https://codeload.github.com/akameco/reducer-tester/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225324174,"owners_count":17456460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diff","jest","react","reducer","redux","snapshot","snapshot-testing","test"],"created_at":"2024-08-03T01:04:00.515Z","updated_at":"2024-11-19T09:09:26.585Z","avatar_url":"https://github.com/akameco.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# reducer-tester\n\n[![Build Status](https://travis-ci.org/akameco/reducer-tester.svg?branch=master)](https://travis-ci.org/akameco/reducer-tester)\n[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)\n\n\u003e reducer tester\n\nSee [how-to-test-reducers](https://github.com/akameco/how-to-test-reducers)\n\n## Install\n\n```\n$ yarn add --dev reducer-tester\n```\n\n## Usage\n\n```js\n// reducer.js\nexport const initialState = { count: 0, other: 'other' }\n\nexport default (state = initialState, action) =\u003e {\n  switch (action.type) {\n    case 'inc':\n      return { ...state, count: state.count + 1 }\n    case 'dec':\n      return { ...state, count: state.count - 1 }\n    default:\n      return state\n  }\n}\n\n// reducer.test.js\nimport reducerTester from 'reducer-tester'\nimport reducer, { initialState } from './reducer'\n\nreducerTester({\n  reducer,\n  state: initialState,\n  tests: [{ type: 'inc' }, { type: 'dec' }],\n})\n```\n\n### Snapshot\n\n```diff\n// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`handle initial state 1`] = `\n\"Snapshot Diff:\nCompared values have no visual difference.\"\n`;\n\nexports[`dec 1`] = `\n\"Snapshot Diff:\n- Before\n+ After\n\n  Object {\n-   \"count\": 0,\n+   \"count\": -1,\n    \"other\": \"other\",\n  }\"\n`;\n\nexports[`inc 1`] = `\n\"Snapshot Diff:\n- Before\n+ After\n\n  Object {\n-   \"count\": 0,\n+   \"count\": 1,\n    \"other\": \"other\",\n  }\n`;\n```\n\n## Full example\n\n```js\nimport reducerTester from 'reducer-tester'\nimport reducer, { initialState } from './reducer'\n\nreducerTester({\n  reducer, // #required\n  state: initialState, // #required\n  tests: [{ type: 'inc' }, { type: 'dec' }], // #required\n  initialTest: false, // # optional, default: true\n  titlePrefix: 'handle ', // # optional, default: ''\n})\n```\n\n```diff\n// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`handle dec 1`] = `\n\"Snapshot Diff:\n- Before\n+ After\n\n  Object {\n-   \"count: 0,\n+   count: -1,\n  }\n`;\n\nexports[`handle inc 1`] = `\n\"Snapshot Diff:\n- Before\n+ After\n\n  Object {\n-   count: 0,\n+   count: 1,\n  }\n`;\n```\n\n### Tips\n\n#### Atom Editor User\n\nInstall `language-diff` and `file-types`. And open `config.json` and edit as blow.\n\n```cson\n\"*\":\n  \"file-types\":\n    \"\\\\.js\\\\.snap$\": \"source.diff\"\n```\n\nHooray! Very readable!\n\n![68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f31353331392f64666537363137312d323735322d646265302d613038652d6330633436646330396264662e706e67 (495×575)](https://camo.qiitausercontent.com/d621872e2fedd535ccdb694170499d2ee7031080/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f31353331392f64666537363137312d323735322d646265302d613038652d6330633436646330396264662e706e67)\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore --\u003e\n\u003ctable\u003e\u003ctr\u003e\u003ctd align=\"center\"\u003e\u003ca href=\"http://akameco.github.io\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/4002137?v=4\" width=\"100px;\" alt=\"akameco\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eakameco\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/reducer-tester/commits?author=akameco\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/akameco/reducer-tester/commits?author=akameco\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/akameco/reducer-tester/commits?author=akameco\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"#infra-akameco\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e\u003c/td\u003e\u003ctd align=\"center\"\u003e\u003ca href=\"https://adhrinae.github.io\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/14539203?v=4\" width=\"100px;\" alt=\"Ahn Dohyung\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAhn Dohyung\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/reducer-tester/commits?author=adhrinae\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/kinakobo\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/17736005?v=4\" width=\"100px;\" alt=\"kinakobo\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ekinakobo\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/akameco/reducer-tester/commits?author=kinakobo\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!\n\n## License\n\nMIT © [akameco](http://akameco.github.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakameco%2Freducer-tester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakameco%2Freducer-tester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakameco%2Freducer-tester/lists"}