【发布时间】:2017-02-23 00:05:11
【问题描述】:
我正在尝试测试这个动作创建器:
export const fetchAllItems = (topicIds)=>{
return (dispatch)=>{
topicIds.forEach((topicId, index, array)=>{
const last = index+1 == array.length;
dispatch(fetchItems(topicId, last));
});
};
};
我想断言fetchItems 已经被调用了两次——第一次是1, false,第二次是2, true。我试过redux-mock-store,但不确定我是否正确使用它:
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
const store = mockStore();
store.dispatch(fetchAllItems([1, 2])).then(()=>{
console.log(store.getActions()); //Throws error: TypeError: Cannot read property 'then' of undefined
});
我也尝试过模拟 dispatch 和 fetchItems,但似乎也无法正常工作。
【问题讨论】:
-
是否需要在
fetchAllItems返回的函数中返回Promise?
标签: javascript reactjs redux react-redux redux-thunk