chai-redux-mock-store

1.1.0 • Public • Published

Redux Mock Store chai helpers

BuildStatus

A set of helpers to use with chaijs and redux-mock-store.

Install

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

Setup:

In a tests/helpers.js file put the following content:

import chai from 'chai';
import chaiReduxMockStore from 'chai-redux-mock-store';
 
 
chai.use(chaiReduxMockStore);

Run your tests with this file loaded.

For instance if you use mocha:

mocha --require tests/helpers.js src/**/*-test.js

Examples

dispatchedActions

it('should work', () => {
  const store = createMockStore();
 
  store.dispatch({ type: 'MyAction' });
  store.dispatch({ type: 'MyOtherAction', payload: 'Foo' });
 
  expect(store).to.have.dispatchedActions([
    { type: 'MyAction' },
    { type: 'MyOtherAction', payload: 'Foo' },
  ]);
});
 
it('should work with contain', () => {
  const store = createMockStore();
 
  store.dispatch({ type: 'MyAction' });
  store.dispatch({ type: 'MyOtherAction', payload: 'Foo' });
 
  expect(store).to.contain.dispatchedActions([
    { type: 'MyOtherAction', payload: 'Foo' },
  ]);
});
 
it('should work with function matcher', () => {
  const store = createMockStore();
 
  store.dispatch({ type: 'MyAction' });
  store.dispatch({ type: 'MyOtherAction', payload: 'Foo' });
 
  expect(store).to.have.dispatchedActions([
    { type: 'MyAction' },
    (action) => expect(action).to.have.property('payload', 'Foo'),
  ]);
});

dispatchedTypes

it('should work', () => {
  const store = createMockStore();
 
  store.dispatch({ type: 'MyAction' });
  store.dispatch({ type: 'MyOtherAction', payload: 'Foo' });
 
  expect(store).to.have.dispatchedTypes(['MyAction', 'MyOtherAction']);
});
 
it('should work with contain', () => {
  const store = createMockStore();
 
  store.dispatch({ type: 'MyAction' });
  store.dispatch({ type: 'MyOtherAction', payload: 'Foo' });
 
  expect(store).to.contain.dispatchedTypes(['MyOtherAction']);
});

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i chai-redux-mock-store

    Weekly Downloads

    2

    Version

    1.1.0

    License

    ISC

    Last publish

    Collaborators

    • themouette