Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including chai-redux-mock-store with all npm packages installed. Try it out:

var chaiReduxMockStore = require("chai-redux-mock-store")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

chai-redux-mock-store v1.1.0

Chai plugin for redux-mock-store

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']);
});

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free