npm install describe-redux
describeRedux()
is a substitute for regular describe()
.
Under the hood it creates a redux store and passes an object containing the store, it's state getter
and bound actions to the callback.
In the examples the typescript-fsa
lib is used to create actions, but it should not make any difference.
It has the following signature:
function describeRedux<S extends {}, A extends ActionCreatorsMapObject>(
description: string,
reducer: Reducer<S>,
initialState: S,
actions: A,
callback: (redux: DescribeReduxContext<S, A>) => void
): void;
The callback argument has the following type
type DescribeReduxContext<Sextends {}, A extends ActionCreatorsMapObject> = {
store: Store<S>;
state: Readonly<S>;
actions: A;
};
A full example can be found under the examples
folder
import { expect } from 'chai';
import { describeRedux } from 'describe-redux';
import * as actions from './actions';
import { initialState, reducer } from './store';
describe('Test store', () => {
describeRedux(
`action ${actions.addItem.type}`,
reducer,
initialState,
actions,
redux => {
it('should add item', () => {
redux.actions.addItem({id: 'test-id'});
expect(redux.state.items).to.eql(['test-id']);
});
});
});