【发布时间】:2019-07-20 00:03:44
【问题描述】:
我正在测试这个传奇
export function* foo() {
yield put(actions.start());
yield put(actions.bar({
onSuccess: () => {
// do something
},
onFailed: () => {
// do something else
}
}));
yield put(userActions.done());
}
这是我的测试
it('should test foo saga, and put start, bar and done actions', () => {
// assertions / expect
testSaga(sagas.foo)
.next()
.put(actions.start())
.next()
.put(
actions.bar({
onSuccess: () => {},
onFailed: () => {},
}),
)
.next()
.put(actions.done())
.next()
.isDone();
});
当我从 saga 中删除有效负载并测试它没有问题通过时,但是当我添加有效负载(不仅是 onSuccess 和 onFailed 回调的任何内容)时,它会向我显示此错误
Assertion failed: put effects do not match
Expected
--------
{
channel: null,
action:
{ type: 'BAR',
payload:
{
onSuccess: [Function: onSuccess],
onFailed: [Function: onFailed]
}
}
}
Actual
------
{
channel: null,
action:
{ type: 'BAR',
payload:
{
onSuccess: [Function: onSuccess],
onFailed: [Function: onFailed]
}
}
}
有趣的是实际负载和预期负载相等,但测试没有通过!
【问题讨论】:
标签: reactjs redux jestjs redux-saga redux-saga-test-plan