{"id":17621084,"url":"https://github.com/workable/redux-test-belt","last_synced_at":"2025-06-14T08:37:14.199Z","repository":{"id":57351731,"uuid":"68220849","full_name":"Workable/redux-test-belt","owner":"Workable","description":"Flexible Redux testing utilities","archived":false,"fork":false,"pushed_at":"2024-04-15T15:06:48.000Z","size":449,"stargazers_count":17,"open_issues_count":5,"forks_count":2,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-04-23T10:42:13.069Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/Workable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-14T15:59:40.000Z","updated_at":"2023-04-17T14:29:02.000Z","dependencies_parsed_at":"2024-10-22T22:40:16.591Z","dependency_job_id":null,"html_url":"https://github.com/Workable/redux-test-belt","commit_stats":{"total_commits":11,"total_committers":3,"mean_commits":"3.6666666666666665","dds":0.6363636363636364,"last_synced_commit":"d0751b7979c4098a26b27109121b4909cbb64ed7"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fredux-test-belt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fredux-test-belt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fredux-test-belt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fredux-test-belt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Workable","download_url":"https://codeload.github.com/Workable/redux-test-belt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251749121,"owners_count":21637457,"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":[],"created_at":"2024-10-22T20:10:29.967Z","updated_at":"2025-04-30T17:21:59.638Z","avatar_url":"https://github.com/Workable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redux Test Belt\n[![build status](https://img.shields.io/travis/Workable/redux-test-belt/master.svg?style=flat-square)](https://travis-ci.org/Workable/redux-test-belt)\n[![npm version](https://img.shields.io/npm/v/redux-test-belt.svg?style=flat-square)](https://www.npmjs.com/package/redux-test-belt)\n[![npm version](https://img.shields.io/npm/dm/redux-test-belt.svg?style=flat-square)](https://www.npmjs.com/package/redux-test-belt)\n\nRedux-test-belt is a JavaScript testing utility for Redux that makes it easier to assert, isolate, manipulate, and traverse your store's output.\n\nRedux-test-belt's API is meant to be flexible by mimicking / extending Redux's store functionality. Furthermore, Redux-test-belt is unopinionated regarding which test runner, assertion library or how your application is constructed.\n\n\n## Installation\n\nTo get started with Redux-test-belt, you can simply install it with NPM:\n\n    npm install --save-dev redux-test-belt\n\nRedux-test-belt is currently compatible with all versions of Redux.\n\n## Table of Contents\n\n* [Quickstart](#quickstart)\n* [API](#api)\n    * [initStore](#initstore)\n    * [mockStore](#mockstore)\n      * [Store utilities \u0026 helpers](#store-utilities--helpers)\n      * [store.dispatch](#storedispatch)\n      * [store.getState](#storegetstate)\n      * [Actions utilities](#actions-utilities)\n      * [Async utilities](#async-utilities)\n      * [Blocking utilities](#blocking-utilities)\n      * [Orphans utilities](#orphans-utilities)\n    * [Middlewares](#mock)\n      * [blockMiddleware](#blockmiddleware)\n      * [actionsLoggerMiddleware](#actionsloggermiddleware)\n      * [orphansMiddleware](#orphansmiddleware)\n      * [promiseMiddleware](#promisemiddleware)\n* [Examples](examples)\n  * [Basic React example](examples/react-example)\n  * [Async testing](examples/react-async-example)\n\n## Quickstart\n\nRedux-test-belt uses store enhanchers in order to improve the testing mechanisms.\nGetting started is a simple as:\n\n```js\n  import initStore from 'redux-test-belt';\n\n  const mockStore = initStore();\n  const store = mockStore({});\n\n  store.dispatch({type: 'START'});\n  store.dispatch({type: 'START'});\n  console.assert(store.getActions().length === 2, \"\u003e\u003e Error\")\n```\n\nRedux-test-belt takes seconds to setup against your testing suite.\nThe following example uses Ava as a test runner:\n\n```js\nimport initStore from 'redux-test-belt';\nimport { describe } from 'ava-spec';\nimport thunk from 'redux-thunk';\n\ndescribe('e2e test', it =\u003e {\n\n  it.beforeEach(t =\u003e {\n    // Before store's creation, we need to bootstrap redux-test-belt\n    // Any additional middlewares may be passed along store's creation\n    t.context.mockStoreWithMiddleware = initStore([thunk]);\n  });\n\n  it.afterEach(t =\u003e {\n    delete t.context.mockStoreWithMiddleware;\n  });\n\n  it('dispatches increment action', t =\u003e {\n    // setup\n    const store = t.context.mockStoreWithMiddleware({});\n    const action = { type: 'INCREMENT' };\n    store.dispatch(action);\n    t.deepEqual(store.getActions(), [action]);\n  });\n\n});\n```\n\n## API\n\n## initStore\n    initStore(middlewares?: Object) =\u003e mockStoreWrapper\n\n#### Arguments\n  1. `middlewares` (`Array of middlewares` [optional])\n\n#### Description\n`initStore()` is a single entry point bootstrapping Redux-test-belt's store. It accepts any additional middlewares that\nmay be required by each test. initStore exposes a single constructor function.\n\n#### Example usage\n\n```js\n  // Usage without middlewares\n  import initStore from '../src/modules/mockStore';\n\n  const storeInit = initStore();\n```\n\n```js\n  // Usage with middlewares\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import promise from 'redux-promise';\n\n  const storeInit = initStore([thunk, promise]);\n```\n\n## mockStore\n    mockStore(initialState = null : Object,\n      reducers = (currentState, action) =\u003e currentState: Function ,\n      blockCheck = (...args) =\u003e true : Function) =\u003e Store\n\n#### Arguments\n  1. `initialState` (`any` [optional]) The initial state of the store\n  2. `reducers` (`Function` [optional]) A reducing function that returns the next state tree, given the current state tree and an action to handle.   [`combineReducers`](http://redux.js.org/docs/api/combineReducers.html) may be used in order to invoke multiple reducers.\n  3. `blockCheck` (`Function` [optional]) . `blockCheck` is a predicate function used along with the `blockMiddleware`. It is primarily used in order to limit down the range of the actions invoked during our application's testing.\n\n#### Description\n`mockStore()` is an extended version of Redux's `[createStore()](http://redux.js.org/docs/api/createStore.html)`. Using store enhancers it adds additional testing utilities combining separated middlewares. This is mainly the heart of each testing unit.\n\n#### Example usage\n\n```js\n  // use mockStore with initial state\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n  test(t =\u003e {\n\n    const storeInit = initStore();\n    const store = t.context.mockStore({ state: 1, items:[] });\n\n  });\n```\n\n```js\n  // use mockStore with initial state and a reducer\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n  test(t =\u003e {\n\n    const storeInit = initStore();\n\n    // reducer\n    function reducer(state = [], action) {\n      switch (action.type) {\n      case 'ADD_TODO':\n        return state.concat([action.payload]);\n      default:\n        return state;\n      }\n    };\n\n    const store = t.context.mockStore({}, reducer);\n  });\n```\n\n```js\n  // use mockStore along with combineReducers\n  import initStore from 'redux-test-belt';\n  import { combineReducers } from 'redux';\n  import test from 'ava';\n  test(t =\u003e {\n\n    const storeInit = initStore();\n\n    // reducer\n    function firstReducer(state = [], action) {\n      switch (action.type) {\n      case 'ADD_TODO':\n        return state.concat([action.payload]);\n      default:\n        return state;\n      }\n    };\n\n    function secondReducer(state = [], action) {\n      switch (action.type) {\n      case 'INCREMENT':\n        return state + 1;\n      case 'DECREMENT':\n        return state - 1;\n      default:\n        return state\n      }\n    };\n\n    const reducers = combineReducers({\n      firstReducer,\n      secondReducer\n    });\n\n    const store = t.context.mockStore({}, reducers);\n  });\n```\n\n```js\n  // use mockStore with initial state, a reducer and a block checking predicate function\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n  test(t =\u003e {\n\n    const storeInit = initStore();\n\n    // reducer\n    function reducer(state = [], action) {\n      switch (action.type) {\n      case 'ADD_TODO':\n        return state.concat([action.payload]);\n      default:\n        return state;\n      }\n    };\n\n    function()\n\n    const store = t.context.mockStore({}, reducer);\n  });\n```\n\n## Store utilities \u0026 helpers\n`mockStore()` returns a Redux store instance extended by several testing utilities. Most of the packed functionality is separated in isolated middlewares as well, providing a clean and powerful testing workflow.\n\n## store.dispatch\n    store.dispatch(action?: Object)\n\n#### Arguments\n  1. `action` (`Object`) A plain object describing the change that makes sense for your application. Actions are the only way to get data into the store. As a result, any kind of data indicating a store change, whether from UI events, network callbacks, or other sources such as WebSockets needs to eventually be dispatched as actions.\n\n#### Description\n  `dispatch()` is used to dispatch actions to the store. This is the only way to trigger a state change. The functionality provided from this method is identical to [Redux's dispatch()](http://redux.js.org/docs/api/Store.html#dispatch).\n\n#### Example usage\n  ```js\n  // use mockStore with initial state\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n  test(t =\u003e {\n\n    const storeInit = initStore();\n    const store = t.context.mockStore({});\n    store.dispatch({ type: 'INCREMENT' });\n  });\n  ```\n\n\n## store.getState\n    store.getState() =\u003e state\n\n#### Description\n`getState()` returns the current state tree of your application.\nIt is equal to the last value returned by the store’s reducer. The functionality provided from this method is identical to [Redux's getState()](http://redux.js.org/docs/api/Store.html#getState).\n\n\n## Actions utilities\n#### Introduction\nIn most cases testing a Redux application includes testing against the state of the store. In the other side, unit test may require checking the actions dispatched. Redux-test-belt comes with a set of helper functions providing an ease applying assertions on the action chain.\n\n## store.getActions\n    store.getActions() =\u003e [Object]\n\n#### Description\n`store.getActions()` returns a list with all the actions dispatched against the store. Keep in mind, that the actions dispatched may be [asynchronous](http://redux.js.org/docs/advanced/AsyncActions.html), `store.getActions()` keeps track on the actions based on time on when the actions are fired through the action creators.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n\n  test(t =\u003e {\n\n    const storeInit = initStore();\n    const store = t.context.mockStore({});\n    const actions = [\n      { type: 'BAR' },\n      { type: 'foo', payload: 'PAYLODED' }\n    ];\n    store.dispatch(actions[0]);\n    store.dispatch(actions[1]);\n    t.deepEqual(store.getActions(), actions);\n  });\n```\n\n## store.hasActions\n    store.hasActions(matcher? Object(s) || String(s) ) =\u003e Boolean\n\n#### Arguments\n  1. `matcher` (`Object(s) || String(s)`) Using matcher you may filter down the actions dispatched on the store. A matcher may be one or more action objects deeply matching the action queue or even just the action type(s).\n\n#### Description\nIn large scale applications testing against the actions dispatched may be tedious. Matching a list of actions usually requires an assertion library, like [Chai](http://chaijs.com/) and lots of configuration. Redux-test-belt is packed with the `store.hasActions()` as utility helper.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n\n  test(t =\u003e {\n\n    const storeInit = initStore();\n    const store = t.context.mockStore({});\n    store.dispatch({ type: 'ACTION_1' });\n    store.dispatch({ type: 'ACTION_2', payload: 'PAYLODED' });\n    store.dispatch({ type: 'ACTION_3' });\n\n    // Τesting against a superset of action objects\n    t.true(store.hasActions(\n      { type: 'ACTION_1' },\n      { type: 'ACTION_2', payload: 'PAYLODED' }));\n\n    t.true(store.hasActions(\n      { type: 'ACTION_3' },\n      { type: 'ACTION_1' }));\n\n  });\n```\n\n```js\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n\n  test(t =\u003e {\n\n    const storeInit = initStore();\n    const store = t.context.mockStore({});\n    store.dispatch({ type: 'ACTION_1' });\n    store.dispatch({ type: 'ACTION_2', payload: 'PAYLODED' });\n    store.dispatch({ type: 'ACTION_3' });\n\n    // Τesting against a superset of action types\n    t.true(store.hasActions('ACTION_1', 'ACTION_2'));\n    t.true(store.hasActions('ACTION_3', 'ACTION_2'));\n\n  });\n```\n\n## store.clearActions\n    store.clearActions() =\u003e []\n\n#### Description\nTo help a test suite DRY up any duplicated setup and teardown code, Redux-test-belt provides the `store.clearActions()` method. In particular, `store.clearActions()` clears up the actions recorded during the store's lifecycle. It may be used on global before \u0026 after hooks, in order to keep each test isolated and independent.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n\n  test(t =\u003e {\n\n    const storeInit = initStore();\n    const store = t.context.mockStore({});\n    store.dispatch({ type: 'ACTION_1' });\n    store.dispatch({ type: 'ACTION_2' });\n\n    t.true(store.hasActions('ACTION1', 'ACTION2'));\n\n    store.clearActions();\n    t.deepEqual(store.getActions(), []);\n\n  });\n```\n\n```js\n  import initStore from 'redux-test-belt';\n  import test from 'ava';\n\n  test.beforeEach(t =\u003e {\n    // Mock the store before each test\n    t.context.storeInit = initStore();\n    t.context.store = t.context.mockStore({});\n  });\n\n  test.afterEach(t =\u003e {\n      // Clear all the actions after each test\n      t.context.store.clearActions();\n  });\n\n  test(t =\u003e {\n\n    t.context.dispatch({ type: 'ACTION_1' });\n    t.context.dispatch({ type: 'ACTION_2' });\n\n    t.true(t.context.hasActions('ACTION1', 'ACTION2'));\n\n  });\n```\n\n## Async utilities\n\n#### Introduction\nRedux applications may use asynchronous action creators; testing asynchronous actions that will be processed by reducers synchronously it's hard to deal with, though. Redux-test-belt provides async helper methods in order to write serialized tests. Keep in mind that async action handling requires using a thunk middleware for Redux like [redux-thunk](https://github.com/gaearon/redux-thunk).\n\n## store.getPromises\n    store.getPromises() =\u003e [Object]\n\n#### Description\n`store.getPromises()` grabs all the actions dispatched on the store that are encapsulated as Promise objects.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test.serial(t =\u003e {\n\n    function superAction() {\n      return {\n        type: 'ACTION_DISPATCHED'\n      };\n    }\n\n    function asynchronousAction() {\n      return dispatch =\u003e {\n        return Promise.resolve()\n          .then(() =\u003e dispatch(superAction()));\n      };\n    }\n\n    const storeInit = initStore([thunk]);\n    const store = t.context.mockStore({});\n\n    return store.dispatch(asynchronousAction())\n      .then(() =\u003e {\n        t.is(store.getPromises().length, 1);\n      });\n\n  });\n```\n\n## store.getPending\n    store.getPending() =\u003e [Object]\n\n#### Description\n`store.getPending()` returns all the actions dispatched on the store that are encapsulated as Promises and their initial state is not fulfilled, nor rejected yet.\n\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test(t =\u003e {\n\n    function superAction() {\n      return {\n        type: 'ACTION_DISPATCHED'\n      };\n    }\n\n    function asynchronousAction() {\n      return dispatch =\u003e {\n        return Promise.all([\n          dispatch(superAction())\n        ])\n      };\n    }\n    const storeInit = initStore([thunk]);\n    const store = t.context.mockStore({});\n    // the middleware messes the actions clear them :)\n    store.dispatch(asynchronousAction())\n    t.is(store.getPending().length, 1);\n  });\n```\n\n## store.getRejected\n    store.getRejected() =\u003e [Object]\n\n#### Description\n`store.getRejected()` returns all the actions dispatched on the store that are encapsulated as Promises and yet settled.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test.serial(t =\u003e {\n\n    function superAction() {\n      return {\n        type: 'ACTION_DISPATCHED'\n      };\n    }\n\n    function asynchronousAction() {\n      return dispatch =\u003e {\n        return Promise.reject()\n          .then(() =\u003e dispatch(superAction()));\n      };\n    }\n\n    const store = t.context.mockStore({});\n    //  the middleware messes the actions clear them :)\n    return store.dispatch(asynchronousAction())\n      .then(() =\u003e {\n        t.is(store.getPending().length, 0);\n        t.is(store.getRejected().length, 1);\n        t.is(store.getPromises().length, 1);\n\n      });\n  });\n```\n\n## store.getResolved\n    store.getResolved() =\u003e [Object]\n\n#### Description\n`store.getResolved()` returns all the actions dispatched on the store that are encapsulated as Promises and settled, or locked into a promise chain.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test.serial(t =\u003e {\n\n    function superAction() {\n      return {\n        type: 'ACTION_DISPATCHED'\n      };\n    }\n\n    function asynchronousAction() {\n      return dispatch =\u003e {\n        return Promise.resolve()\n          .then(() =\u003e dispatch(superAction()));\n      };\n    }\n\n    const store = t.context.mockStore({});\n    //  the middleware messes the actions clear them :)\n    return store.dispatch(asynchronousAction())\n      .then(() =\u003e {\n        t.is(store.getPending().length, 0);\n        t.is(store.getResolved().length, 1);\n        t.is(store.getPromises().length, 1);\n\n      });\n  });\n```\n\n## store.clearPromises\n    store.clearPromises() =\u003e []\n\n#### Description\nTo help a test suite DRY up any duplicated setup and teardown code, Redux-test-belt provides the `store.clearPromises()` method. In particular, `store.clearPromises()` clears up the recorded actions that are encapsulated as Promise objects during store's lifecycle. It may used on global before \u0026 after hooks in order to keep each test isolated and independent .\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test.serial(t =\u003e {\n\n    function superAction() {\n      return {\n        type: 'ACTION_DISPATCHED'\n      };\n    }\n\n    function asynchronousAction() {\n      return dispatch =\u003e {\n        return Promise.resolve()\n          .then(() =\u003e dispatch(superAction()));\n      };\n    }\n\n    const store = t.context.mockStore({});\n    //  the middleware messes the actions clear them :)\n    return store.dispatch(asynchronousAction())\n      .then(() =\u003e {\n        t.is(store.getResolved().length, 1);\n        t.is(store.getPromises().length, 1);\n\n        store.clearPromises();\n\n        t.is(store.getResolved().length, 0);\n        t.is(store.getPromises().length, 0);\n\n      });\n  });\n```\n\n## Blocking utilities\n\n#### Introduction\nIn complex applications where lots of actions take place testing might be bloated. Redux-test-belt provides a set of utilities which enable users to filter the actions dispatched, clean up any redundant actions as well as to prevent state's manipulation. Each blocked action is stored for later use and may be accessed on demand later. All the blocked actions are actually dispatched on the store in order to keep Redux in place, the action type is marked as `✋BLOCKED_ACTION`  whilst the payload holds the very first action created.\n\n#### Setup\nAs it was mentioned earlier, you may pass a predicate function as a parameter during [mockStore](#mockstore)'s instantiation. Blocking prediction may take place, either or the state or the action that takes place.\n\n```js\n  import initStore from 'redux-test-belt';\n  const mockStore = initStore([]);\n\n  const reducer = (currentState, action) =\u003e currentState;\n  const blockCheck = (currentState, action) =\u003e {\n    return (action.type === 'BLOCKED') ? false : true;\n  }\n  const store = mockStore({},reducer, blockCheck);\n  store.dispatch({ type: 'BLOCKED' });\n  store.dispatch({ type: 'NON-BLOCKED' });\n```\n\n## store.getBlocked\n    store.getBlocked() =\u003e [actions]\n\n#### Description\n`store.getBlocked()` returns all the blocked actions filtered from the passed predicate function.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test.serial(t =\u003e {\n    const mockStore = initStore([]);\n\n    const reducer = (currentState, action) =\u003e currentState;\n    const blockCheck = (currentState, action) =\u003e {\n      return (action.type === 'BLOCKED') ? false : true;\n    }\n    const store = mockStore({},reducer, blockCheck);\n    store.dispatch({ type: 'BLOCKED' });\n    store.dispatch({ type: 'NON-BLOCKED' });\n    t.deepEqual(store.getBlocked(),[{ type: 'BLOCKED' }]);\n  });\n```\n\n\n## store.clearBlocked\n    store.clearBlocked() =\u003e []\n\n#### Description\n`store.clearBlocked()` clears all the blocked actions stored.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test(t =\u003e {\n    const mockStore = initStore([]);\n\n    const reducer = (currentState, action) =\u003e currentState;\n    const blockCheck = (currentState, action) =\u003e false;\n    const store = mockStore({},reducer, blockCheck);\n\n    store.dispatch({ type: 'BLOCKED' });\n    t.deepEqual(store.getBlocked(),[{ type: 'BLOCKED' }]);\n    store.clearBlocked();\n    t.deepEqual(store.getBlocked(),[]);\n  });\n```\n\n## store.hasBlocked\n    store.hasBlocked(matcher? Object(s) || String(s) ) =\u003e Boolean\n\n#### Arguments\n  1. `matcher` (`Object(s) || String(s)`) Using matcher you may filter down the repository of blocked actions which is being retained inside the store's instance. A matcher may be one or more action objects deeply matching the blocked action queue or even just the action type(s).\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test(t =\u003e {\n    const mockStore = initStore([]);\n\n    const reducer = (currentState, action) =\u003e currentState;\n    const blockCheck = (currentState, action) =\u003e false;\n    const store = mockStore({},reducer, blockCheck);\n\n    store.dispatch({ type: 'ACTION1' });\n    store.dispatch({ type: 'ACTION2', payload: 'PAYLODED' });\n    t.true(store.hasBlocked('ACTION1', 'ACTION2'));\n\n    store.dispatch({ type: 'ACTION3' });\n    t.true(store.hasBlocked('ACTION1', 'ACTION2', 'ACTION3'));\n    t.false(store.hasBlocked('whatever', 'ACTION1'));\n  });\n```\n\n\n## Orphans utilities\n\n#### Introduction\nRedux-test-belt declares orphans as actions that don't differentiate or manipulate the actual state. Where lots of action are dispatched simultaneously this feature allows testing to narrow down the results, take action on dead code and improve debugging.\n\n## store.getOrphans\n    store.getOrphans() =\u003e [Object]\n\n#### Description\n`store.getOrphans()` returns a list of actions that didn't change the state upon dispatching.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test(t =\u003e {\n\n    function fakeDispather() {\n      return {\n        type: 'ADD_TODO'\n      }\n    }\n    const mockStore = initStore([]);\n    const store = mockStore({});\n\n    store.dispatch(fakeDispather());\n    store.dispatch(fakeDispather());\n\n    t.is(store.getOrphans().length, 2);\n    t.deepEqual(\n      store.getOrphans(),\n      [{ type: 'ADD_TODO' }, { type: 'ADD_TODO' }]);\n  });\n```\n\n## store.hasOrphans\n    store.hasActions(matcher? Object(s) || String(s) ) =\u003e Boolean\n\n#### Arguments\n  1. `matcher` (`Object(s) || String(s)`) Using matcher you may filter down the orphans' repository. A matcher may be one or more action objects deeply matching the action queue or even just the action type(s).\n\n  #### Example usage\n\n  ```js\n    import initStore from 'redux-test-belt';\n    import thunk from 'redux-thunk';\n    import test from 'ava';\n    test(t =\u003e {\n\n      function fakeDispather() {\n        return {\n          type: 'ADD_TODO'\n        }\n      }\n      const mockStore = initStore([]);\n      const store = mockStore({});\n\n      store.dispatch(fakeDispather());\n      store.dispatch(fakeDispather());\n      t.is(store.hasOrphans('ADD_TODO'), true);\n      t.is(store.hasOrphans({type: 'ADD_TODO' }), true);\n    });\n  ```\n\n## store.clearOrphans\n    store.clearOrphans() =\u003e []\n\n#### Description\n`store.clearOrphans()` truncates the list of orphan actions.\n\n#### Example usage\n\n```js\n  import initStore from 'redux-test-belt';\n  import thunk from 'redux-thunk';\n  import test from 'ava';\n  test(t =\u003e {\n\n    function fakeDispather() {\n      return {\n        type: 'ADD_TODO'\n      }\n    }\n    const mockStore = initStore([]);\n    const store = mockStore({});\n\n    store.dispatch(fakeDispather());\n    store.dispatch(fakeDispather());\n\n    t.is(store.getOrphans().length, 2);\n    t.deepEqual(\n      store.getOrphans(),\n      [{ type: 'ADD_TODO' },{ type: 'ADD_TODO' }]);\n    store.clearOrphans();\n    t.is(store.getOrphans().length, 0);\n  });\n```\n\n## Middlewares\n\n#### Introduction\nWhere default [createStore()](http://redux.js.org/docs/api/createStore.html) is used, it seems a bit redundant to write additional tests using Redux-test-belt's `mockStore()`. Therefore, Redux-test-belt exports each module as a flexible [middleware](http://redux.js.org/docs/advanced/Middleware.html).\n\n\n## blockMiddleware\n\n#### Associated methods\n  * [store.getBlocked](#storegetblocked)\n  * [store.hasBlocked](#storehasblocked)\n  * [store.clearBlocked](#storeclearblocked)\n\n#### Example usage\n\n```js\n  import { createStore } from 'redux';\n  import { blockMiddleware, blockedActions, PREFIX_ACTION } from 'redux-test-belt';\n\n  const blocking = (currentState, action) =\u003e false;\n\n  function reducer(state = [], action) {\n    switch (action.type) {\n      case 'ADD_TODO':\n        return state.concat([ action.payload ])\n      default:\n        return state\n    }\n  }\n\n  let store = createStore(reducer,\n      [ 'Use Redux' ],\n      applyMiddleware.apply(null, [blockMiddleware(blocking)])\n  );\n\n  store.dispatch({\n    type: 'ACTION',\n    text: 'Read the docs'\n  });\n\n  // Expose each method\n  console.log(blockedActions.getBlocked());\n  //Alias: blockedActions.get()\n\n  console.log(blockedActions.hasBlocked('ACTION'));\n  //Alias: blockedActions.has()\n\n  blockedActions.clearBlocked();\n\n  console.log(blockedActions.getBlocked());\n  console.log(PREFIX_ACTION);\n```\n\n## actionsLoggerMiddleware\n\n#### Associated methods\n  * [store.getActions](#storegetactions)\n  * [store.hasActions](#storehasactions)\n  * [store.clearActions](#storeclearactions)\n\n#### Example usage\n\n```js\n  import { createStore } from 'redux';\n  import { loggedActions, actionsLoggerMiddleware } from 'redux-test-belt';\n\n  function reducer(state = [], action) {\n    switch (action.type) {\n      case 'ADD_TODO':\n        return state.concat([ action.payload ])\n      default:\n        return state\n    }\n  }\n\n  let store = createStore(reducer,\n      [ 'Use Redux' ],\n      applyMiddleware.apply(null, [actionsLoggerMiddleware])\n  );\n\n  store.dispatch({\n    type: 'ACTION',\n    text: 'Read the docs'\n  });\n\n  // Expose each method\n  console.log(loggedActions.getActions());\n  // Alias: loggedActions.get()\n\n  console.log(loggedActions.hasActions('ACTION'));\n  // loggedActions.has()\n\n  loggedActions.clearActions();\n  console.log(loggedActions.getActions());\n```\n\n## orphansMiddleware\n\n#### Associated methods\n  * [store.getOrphans](#storegetorphans)\n  * [store.hasOrphans](#storehasorphans)\n  * [store.clearOrphans](#storeclearorphans)\n\n#### Example usage\n\n```js\n  import { createStore } from 'redux';\n  import { orphansMiddleware, orphans } from 'redux-test-belt';\n\n  function reducer(state = [], action) {\n    switch (action.type) {\n      case 'ADD_TODO':\n        return state.concat([ action.payload ])\n      default:\n        return state\n    }\n  }\n\n  let store = createStore(reducer,\n      [ 'Use Redux' ],\n      applyMiddleware.apply(null, [orphansMiddleware])\n  );\n\n  store.dispatch({\n    type: 'ACTION',\n    text: 'Read the docs'\n  });\n\n  // Expose each method\n  console.log(orphans.getOrphans());\n  //Alias: orphans.get()\n\n  console.log(orphans.hasOrphans('ACTION'));\n  //Alias: orphans.has()\n\n  orphans.clearOrphans();\n  console.log(orphans.getOrphans());\n```\n\n## promiseMiddleware\n\n#### Associated methods\n  * [store.getPromises](#storegetpromises)\n  * [store.getPending](#storegetpending)\n  * [store.getRejected](#storegetrejected)\n  * [store.getResolved](#storegetresolved)\n  * [store.getPromises](#storeclearpromises)\n\n#### Example usage\n\n```js\n  import { createStore } from 'redux';\n  import { promiseMiddleware, promises } from 'redux-test-belt';\n\n  function reducer(state = [], action) {\n    switch (action.type) {\n      case 'ADD_TODO':\n        return state.concat([ action.payload ])\n      default:\n        return state\n    }\n  }\n\n  function superAction() {\n    return {\n      type: 'ACTION_DISPATCHED'\n    };\n  }\n\n  function asynchronousAction() {\n    return dispatch =\u003e {\n      return Promise.resolve()\n        .then(() =\u003e dispatch(superAction()));\n    };\n  }\n\n  let store = createStore(reducer,\n      [ 'Use Redux' ],\n      applyMiddleware.apply(null, [promiseMiddleware])\n  );\n\n  store.dispatch(asynchronousAction());\n\n  // Expose each method\n  console.log(promises.getPromises());\n  // Alias: promises.get();\n  console.log(promises.getPending());\n  console.log(promises.getRejected());\n  console.log(promises.getResolved());\n\n  promises.clear();\n  // Alias: promises.clearPromises();\n\n  console.log(promises.getPromises());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkable%2Fredux-test-belt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkable%2Fredux-test-belt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkable%2Fredux-test-belt/lists"}