我正在尝试测试我的一个 saga 函数,其中有一个race. 我的代码和我的测试比赛看起来几乎相同,但比赛测试似乎失败了
// in my saga
yield race({
delay: delay(waitLength),
cancel: take(smartlook.actions.cancelDelay)
});
// part of the test
.race({
delay: delay(recordTimeLength),
cancel: take(smartlookActions.cancelDelay)
})
我已经验证了这一点waitLength并且recordTimeLength是相同的,因为无论如何它们都需要作为测试中上一步的一部分。的take动作都指向完全相同的动作,只是在命名进口略有不同,由于名称冲突。
当我运行我的测试时,我得到
SagaTestError:
race expectation unmet:
Expected
--------
{ delay:
{ _40: 0,
_65: 0,
_55: null,
_72: null,
'@@redux-saga/CANCEL_PROMISE': [Function] },
cancel:
{ '@@redux-saga/IO': true,
TAKE: { pattern: { [Function: actionCreator] toString: [Function] } } } }
Actual:
------
1. { delay:
{ _40: 1,
_65: 0,
_55: null,
_72:
{ onFulfilled: { [Function: currCb] cancel: [Object] },
onRejected: [Function],
promise: { _40: 0, _65: 0, _55: null, _72: null } },
'@@redux-saga/CANCEL_PROMISE': [Function] },
cancel:
{ '@@redux-saga/IO': true,
TAKE: { pattern: { [Function: actionCreator] toString: [Function] } } } }
我不知道为什么delay测试中的代码与实际代码不同,如果有人知道这应该如何工作,请告诉我。
为下面的上下文粘贴更多代码
在传奇中:
export function* recordThenWait(waitLength) {
const isRecording = yield select(smartlook.selectors.getSmartlookIsRecording);
if (!isRecording) {
yield put(smartlook.actions.resumeRecording());
}
yield race({
delay: delay(waitLength),
cancel: take(smartlook.actions.cancelDelay)
});
yield put(smartlook.actions.pauseRecording());
}
在测试中(测试不仅仅是上面的功能):
return expectSaga(Smartlook, {recordTimeLength, now})
.withState(initialState)
.dispatch(appStarted())
.put(smartlookActions.recordAppStart())
.fork(smartlook.recordThenWait, recordTimeLength)
.put(smartlookActions.resumeRecording()) //works till here
.race({
delay: delay(recordTimeLength),
cancel: take(smartlookActions.cancelDelay)
})
.put(smartlookActions.pauseRecording())
.run();
斯蒂芬大帝
相关分类