A mock store for testing Redux async action creators and middleware.

License: MIT

Language: JavaScript

Keywords: javascript, redux, test

redux-mock-store Circle CI


A mock store for testing Redux async action creators and middleware. The mock store will create an array of dispatched actions which serve as an action log for tests.

Please note that this library is designed to test the action-related logic, not the reducer-related one. In other words, it does not update the Redux store. If you want a complex test combining actions and reducers together, take a look at other libraries (e.g., redux-actions-assertions). Refer to issue #71 for more details.


npm install redux-mock-store --save-dev


yarn add redux-mock-store --dev


Synchronous actions

The simplest usecase is for synchronous actions. In this example, we will test if the addTodo action returns the right payload. redux-mock-store saves all the dispatched actions inside the store instance. You can get all the actions by calling store.getActions(). Finally, you can use any assertion library to test the payload.

import configureStore from 'redux-mock-store' //ES6 modules
const { configureStore } = require('redux-mock-store') //CommonJS

const middlewares = []
const mockStore = configureStore(middlewares)

// You would import the action from your codebase in a real scenario
const addTodo = () => ({ type: 'ADD_TODO' })

it('should dispatch action', () => {

  // Initialize mockstore with empty state
  const initialState = {}
  const store = mockStore(initialState)

  // Dispatch the action

  // Test if your store dispatched the expected actions
  const actions = store.getActions()
  const expectedPayload = { type: 'ADD_TODO' }

Asynchronous actions

A common usecase for an asynchronous action is a HTTP request to a server. In order to test those types of actions, you will need to call store.getActions() at the end of the request.

import configureStore from 'redux-mock-store'
import thunk from 'redux-thunk'

const middlewares = [thunk] // add your middlewares like `redux-thunk`
const mockStore = configureStore(middlewares)

// You would import the action from your codebase in a real scenario
function success() {
  return {

function fetchData () {
  return dispatch => {
    return fetch('/users.json') // Some async action with promise
      .then(() => dispatch(success()))

it('should execute fetch data', () => {
  const store = mockStore({})

  // Return the promise
  return store.dispatch(fetchData())
    .then(() => {
      const actions = store.getActions()


configureStore(middlewares?: Array) => mockStore: Function

Configure mock store by applying the middlewares.

mockStore(getState?: Object,Function) => store: Function

Returns an instance of the configured mock store. If you want to reset your store after every test, you should call this function.

store.dispatch(action) => action

Dispatches an action through the mock store. The action will be stored in an array inside the instance and executed.

store.getState() => state: Object

Returns the state of the mock store.

store.getActions() => actions: Array

Returns the actions of the mock store.


Clears the stored actions.

store.subscribe(callback: Function) => unsubscribe: Function

Subscribe to the store.

store.replaceReducer(nextReducer: Function)

Follows the Redux API.

Old version (< 1.x.x)


The following versions are exposed by redux-mock-store from the package.json:

  • main: commonJS Version
  • module/js:next: ES Module Version
  • browser : UMD version


The MIT License

Project Statistics

Sourcerank 17
Repository Size 117 KB
Stars 2,083
Forks 128
Watchers 18
Open issues 20
Dependencies 355
Contributors 31
Tags 11
Last updated
Last pushed

Top Contributors See all

Dmitry Zaets Arnaud Bénard Sam Bason Mayank Jethva Kyle Lamse Brian Vaughn David Jensen Braulio Diez Tom Beddard Haroen Viaene Alexandre Lima Ben Neill Julian Fell Chris Blossom Tom Anthony Ng LeoTM butlersrepos Dylan Parry Jeungmin Oh

Packages Referencing this Repo

A mock store for your testing your redux async action creators and middleware. This is a fork of ...
Latest release 0.0.1 - Published - 2.08K stars
[![Circle CI](](h...
Latest release 0.0.2 - Published - 2.08K stars
A mock store for testing your redux async action creators and middleware
Latest release 1.5.4 - Updated - 2.08K stars

Recent Tags See all

v1.5.3 June 13, 2018
v1.5.0 January 26, 2018
v1.4.0 November 05, 2017
v1.2.3 April 09, 2017
v1.0.3 May 20, 2016
v1.0.2 March 10, 2016
v1.0.1 March 10, 2016
v1.0.0 February 25, 2016
v0.0.6 January 08, 2016
v0.0.5 January 08, 2016
v0.1.0 January 08, 2016

Interesting Forks See all

A mock store for testing Redux async action creators and middleware.
TypeScript - MIT - Last pushed - 14 stars - 5 forks

Something wrong with this page? Make a suggestion

Last synced: 2019-12-11 13:44:24 UTC

Login to resync this repository