{"id":14967380,"url":"https://github.com/redux-things/redux-actions-assertions","last_synced_at":"2025-04-06T09:09:48.035Z","repository":{"id":57350149,"uuid":"55507277","full_name":"redux-things/redux-actions-assertions","owner":"redux-things","description":"Simplify testing of redux action and async action creators","archived":false,"fork":false,"pushed_at":"2017-01-18T12:19:28.000Z","size":676,"stargazers_count":188,"open_issues_count":8,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T20:03:25.990Z","etag":null,"topics":["assertions","chai","jest","mocha","redux","redux-middleware","unit-testing"],"latest_commit_sha":null,"homepage":"http://redux-things.github.io/redux-actions-assertions/","language":"JavaScript","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/redux-things.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":"2016-04-05T12:48:44.000Z","updated_at":"2023-05-09T10:48:30.000Z","dependencies_parsed_at":"2022-09-16T21:02:04.461Z","dependency_job_id":null,"html_url":"https://github.com/redux-things/redux-actions-assertions","commit_stats":null,"previous_names":["dmitry-zaets/redux-actions-assertions"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redux-things%2Fredux-actions-assertions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redux-things%2Fredux-actions-assertions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redux-things%2Fredux-actions-assertions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redux-things%2Fredux-actions-assertions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redux-things","download_url":"https://codeload.github.com/redux-things/redux-actions-assertions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457803,"owners_count":20941906,"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":["assertions","chai","jest","mocha","redux","redux-middleware","unit-testing"],"created_at":"2024-09-24T13:37:58.080Z","updated_at":"2025-04-06T09:09:47.995Z","avatar_url":"https://github.com/redux-things.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-actions-assertions \nAssertions for redux actions testing.\n\nThis library adds assertions for [redux actions](http://redux.js.org/docs/advanced/AsyncActions.html) testing.  \nIt use [redux-mock-store](https://github.com/arnaudbenard/redux-mock-store) to mock redux store.\n\n[![build status](https://img.shields.io/travis/redux-things/redux-actions-assertions/master.svg?style=flat-square)](https://travis-ci.org/redux-things/redux-actions-assertions)\n[![npm version](https://img.shields.io/npm/v/redux-actions-assertions.svg?style=flat-square)](https://www.npmjs.com/package/redux-actions-assertions)\n\n## Supported Assertion Frameworks/Libraries:\n- [chai](https://redux-things.github.io/redux-actions-assertions/chai.html)\n- [expect](https://redux-things.github.io/redux-actions-assertions/expect.html)\n- [expect.js](https://redux-things.github.io/redux-actions-assertions/expectjs.html)\n- [jasmine](https://redux-things.github.io/redux-actions-assertions/jasmine.html)\n- [jest](https://redux-things.github.io/redux-actions-assertions/jest.html)\n- [should](https://redux-things.github.io/redux-actions-assertions/should.html)\n- [tape](https://redux-things.github.io/redux-actions-assertions/tape.html)\n- [pure javascript assertion](https://redux-things.github.io/redux-actions-assertions/javascript.html)\n\nIf you have not found assertion framework/library that you are using - please add comment into [this issue](https://github.com/dmitry-zaets/redux-actions-assertions/issues/3).\n\n## What it does:\n- [Allows to avoid retesting nested action creators](#allows-to-avoid-retesting-nested-action-creators);\n- [Reduces repetitive code of test methods](#reduces-repetitive-code-of-test-methods);\n- [Simplifies initial setup](#simplifies-initial-setup);\n\n### Allows to avoid retesting nested action creators\nIt allows to test only actions that need to be tested.\n\n**Example:**  \nWe have two actions (A, B). Each one makes async http requests.  \nAction A makes a request and if the result is successful it triggers Action B.  \nAction B is also used as an independent action.  \nAction B can be tested separately.  \nTherefore, we don't need to test it again in Action A.  \n\nActions:\n```javascript\nfunction actionA() {\n  return dispatch =\u003e {\n    dispatch(actionAStart());\n    return api.getA().then(response =\u003e {\n        dispatch(actionAFinish(response));\n        dispatch(actionB());\n      }).catch(err =\u003e {\n        dispatch(actionAFailure(err));\n      });\n    };\n}\n\nfunction actionB() {\n  return dispatch =\u003e {\n    dispatch(actionBStart());\n    return api.getB().then(response =\u003e {\n        dispatch(actionBFinish(response));\n      }).catch(err =\u003e {\n        dispatch(actionBFailure(err));\n      });\n    };\n}\n```\n\nWithout:\n```javascript\nconst expectedActions = [\n  { type: action_a_start },\n  { type: action_a_success },   \n  { type: action_b_start }, // retesting of action B\n  { type: action_b_success } // retesting of action B];\nconst store = mockStore({ todos: [] });\nstore.dispatch(actionA()).then(() =\u003e {\n  expect(store.getActions()).toEqual(expectedActions);\n}).then(done).catch(done);\n```\n\nWith:\n```javascript\nexpect(actionA()).withState({ todos: [] }).toDispatch([\n  { type: action_a_start },\n  { type: action_a_success },\n  actionB() // just executing tested action\n], done);\n```\n\n### Reduces repetitive code of test methods\nIt reduces boilerplate of test methods and makes testing fluent.\n\nWithout:\n```javascript\nconst store = mockStore(/* initial state */);\nconst expectedActions = [\n  { type: types.FETCH_TODOS_REQUEST },\n  /* All expected triggered action objects */\n];\nstore.dispatch(fetchData()).then(() =\u003e {\n  const actions = store.getActions();\n  expect(actions).toEqual(expectedActions);\n}).then(done).catch(done);\n```\n\nWith:\n```javascript\nconst expectedActions = [\n  /*All expected triggered action objects or action creator functions*/\n];\nexpect(fetchData()).toDispatchActions(expectedActions, done);\n```\n\nWith using customised store state:\n```javascript\nexpect(fetchData()).withState({/*custom state*/}).toDispatchActions(expectedActions, done);\n```\n\n### Simplifies initial setup\nIt provides singe-time global configuration for middlewares and initial store state.\n\nWithout:\n```javascript\nconst middlewares = [thunk];\nconst mockStore = configureStore(middlewares);\nconst store = mockStore({ /*initial store object*});\n```\nWith:\n```javascript\nregisterMiddlewares([ thunk ]);\n// to set custom initial state \nregisterInitialStoreState(/*object of function*/);\n// to generate initial state of your application\nregisterInitialStoreState(buildInitialStoreState(/*your root reducer*/));\n```\n\n## Installation\n\nUsing [npm](https://www.npmjs.org/):\n\n    $ npm install --save-dev redux-actions-assertions\n\n### Redux middlewares registration\n\n```js\n// using ES6 modules\nimport { registerMiddlewares } from 'redux-actions-assertions';\n\n// using CommonJS modules\nvar registerMiddlewares = require('redux-actions-assertions').registerMiddlewares;\n\n// registration\nregisterMiddlewares([\n  /* Here you need to list your middlewares */\n]);\n```\n\n### Default initial store state registration\n\n**By using state object or function:**\n```js\n// using ES6 modules\nimport { registerInitialStoreState } from 'redux-actions-assertions';\n\n// using CommonJS modules\nvar registerInitialStoreState = require('redux-actions-assertions').registerInitialStoreState;\n\n// registration\nregisterInitialStoreState(/* default initial state object or function */);\n```\n**By using your root reducer:**\n```js\n// using ES6 modules\nimport { buildInitialStoreState, registerInitialStoreState } from 'redux-actions-assertions';\n\n// using CommonJS modules\nvar reduxActionsAssertions = require('redux-actions-assertions');\nvar registerInitialStoreState = reduxActionsAssertions.registerInitialStoreState;\n\n// registration\nregisterInitialStoreState(buildInitialStoreState(/* root reducer function */));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredux-things%2Fredux-actions-assertions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredux-things%2Fredux-actions-assertions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredux-things%2Fredux-actions-assertions/lists"}