redux-test-reducer is a simple module that allows you to cleanly test your Redux reducers.
$ npm install --save-dev redux-test-reducer
This package works with any JavaScript testing framework. Here's an example with Mocha:
var testReducer = require('redux-test-reducer');
// Simple counter reducer from the redux docs
var reducer = function(state, action) {
if (action.type === 'INCREMENT') {
return state + 1;
} else if (action.type === 'DECREMENT') {
return state - 1;
} else {
return state;
}
}
// Load the reducer to create an assertion function
var assertReducer = testReducer(reducer);
describe('#reducer', function() {
it('can increment', function() {
assertReducer({
from: 0,
to: 1,
action: { type: 'INCREMENT' }
});
});
it('can decrement', function() {
assertReducer({
from: 2,
to: 1,
action: { type: 'DECREMENT' }
});
});
});
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new pull request