Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.31 KB

README.md

File metadata and controls

56 lines (40 loc) · 1.31 KB

Circle CI

redux-mock-store

A mock store for your testing your redux async action creators and middleware

Install

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

How to use

// actions.test.js

import configureStore from 'redux-mock-store';

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

// Test in mocha
it('should dispatch action', (done) => {
  const getState = {}; // initial state of the store
  const action = { type: 'ADD_TODO' };
  const expectedActions = [action];

  const store = mockStore(getState, expectedActions, done);
  store.dispatch(action);
})

Custom test function for actions can also be supplied, useful if your actions have a dynamic part.

// Test in mocha
it('should dispatch action', (done) => {
  const getState = {}; // initial state of the store
  const action = { type: 'ADD_TODO' };
  const expectedActions = [(incomingAction) => {
    if (incomingAction.type !== 'ADD_TODO') {
      throw Error('Expected action of type ADD_TODO');
    }
  }];

  const store = mockStore(getState, expectedActions, done);
  store.dispatch(action);
})

License

MIT