0.0.1 • Published 8 years ago

redux-mock-store-jasmine v0.0.1

Weekly downloads
11
License
MIT
Repository
github
Last release
8 years ago

redux-mock-store-jasmine

A mock store for your testing your redux async action creators and middleware. This is a fork of https://github.com/arnaudbenard/redux-mock-store, adding a check for done.fail so that this can also be used with Jasmine.

There is a pull request to the original repo with this change.

Install

npm install redux-mock-store-jasmine --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