我有这样的动作:
export const loadPositions = (accountId, filter) => dispatch => {
dispatch({ type: ActionTypes.SEARCH_RESULTS_PENDING });
return ServiceManager.call(someUrl, {
method: 'GET',
})
.then(({ _embedded: { positions } }) => {
dispatch(updatePositions(positions));
dispatch(filterPositions(filter));
})
};
并测试:
it('should filter positions giving no results', () => {
return store.dispatch(loadPositions(accountId, filter)).then(() => {
const filterAction = findActionByType(store.getActions(), ActionTypes.SEARCH_RESULTS_UPDATED);
const {
payload: { instruments },
} = filterAction;
expect(instruments).toEqual([]);
});
});
我正在使用import configureMockStore from 'redux-mock-store';
问题在于,正在调度filterPositions
的{{1}}从以下调用开始:
SEARCH_RESULT_UPDATED
这取决于应该由export const filterPositions = filter => (dispatch, getState) => {
const positions = selectors.getPositions(getState());
...
}
动作(特别是一个减速器,侦听此动作创建者分配的动作)预先设置的状态。
如何对此进行测试?我猜不可能将reducer插入模拟存储吗?