【发布时间】:2017-12-04 11:47:40
【问题描述】:
我正在使用 jest 进行测试。我正在使用 react 和 redux,我有这个动作:
function getData(id, notify) {
return (dispatch, ...) => {
dispatch(anotherFunction());
Promise.all(['resource1', 'resource2', 'resource3'])
.then(([response1,response2,response3]) => {
// ... handle responses
})
.catch(error => { dispatch(handleError(error)); }
};
}
我一直在寻找 jest 文档如何为此操作设置测试,但我找不到方法。我自己尝试过这样的事情:
it('test description', (done) => {
const expectedActions = [{type: {...}, payload: {...}},{type: {...}, payload: {...}},...];
fetchMock.get('resource1', ...);
fetchMock.get('resource2', ...);
fetchMock.get('resource3', ...);
// ... then the rest of the test calls
});
不成功。那我应该怎么做呢?
【问题讨论】:
标签: javascript reactjs testing redux jestjs