Run sequence of redux actions with provided reducer and initial state.
To test the behavior of reducer with chained actions.
function mathReducer(state = 0, action) {
switch (action.type) {
case 'multiply':
return state * action.payload;
case 'divide':
return state / action.payload;
case 'add':
return state + action.payload;
case 'subtract':
return state - action.payload;
case 'increment':
return state + 1;
default:
return state;
}
}
With redux-actions-sequence you can test this reducer with your favorite test runner:
import reduxActionsSequence from 'redux-actions-sequence';
reduxActionsSequence({
reducer: mathReducer,
state: 3,
actions: [
{ type: 'increment' },
{ type: 'add', payload: 10 },
{ type: 'subtract', payload: 2 },
{ type: 'divide', payload: 3 },
{ type: 'multiply', payload: 5 },
],
});
reduxActionsSequence({
reducer: mathReducer,
actions: [
{ type: 'increment' },
{ type: 'add', payload: 10 },
{ type: 'subtract', payload: 2 },
{ type: 'divide', payload: 3 },
{ type: 'multiply', payload: 5 },
],
});