1.1.0 • Published 8 years ago
chai-redux-mock-store v1.1.0
Redux Mock Store chai helpers
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']);
});