给出一个对动作有效载荷进行操作的传奇,其中action
已被takeLatest
传入,例如
export function* mySaga(action) {
try {
yield all(action.payload.items.map(p => call(doSomething, p)));
}
yield put(actionSuccess());
} catch (error) {
yield put(actionFailed(error));
}
}
export function* watchMySaga() {
yield takeLatest(AN_ACTION, mySaga);
}
如何在action
的{{1}}测试中模拟redux-saga-test-plan
?由于mySaga
为action.payload
,因此我的测试当前抛出错误。
答案 0 :(得分:1)
看起来,您只需将模拟操作对象作为第二个参数传递给expectSaga
,例如
return expectSaga(mySaga, action)
.provide([[...]])
.put(actionSuccess())
.run();