该传奇有多个投手。
export function* changeItemsSaga(action) {
const prerequisite1 = yield select(prerequisite1Selector);
// some processing
yield put(actions.myAction1(payload1));
// some more processing
const prerequisite2 = yield select(prerequisite2Selector);
// some more processing
yield put(actions.myAction2(payload2));
}当传奇回归多重效果时,我该如何写我的投入预期呢?
it('should update items', () =>
expectSaga(sagas.changeItemsSaga, action)
.provide([
[select(prerequisite1), {}],
[select(prerequisite2), {}],
])
.put([actions.myAction1(payload1), actions.myAction2(payload2)])
.run());ExpectSaga单元测试返回以下错误:
Saga test error:
put expectation unmet:
Expected
--------
{ channel: null,
action:
[ { type: 'MY_ACTION_1',
payload: { myItem1: [Object] } },
{ type: 'MY_ACTION_2',
payload: { itemCollection: [Object] } } ] }
Actual:
------
1. { channel: null,
action:
{ type: 'MY_ACTION_1',
payload:
{ myItem1:
{ index: 0,
childItem1: [Object],
childItem2: [Object] } } } }
2. { channel: null,
action:
{ type: 'MY_ACTION_2',
payload: { itemCollection: [ [Object] ] } } }这个也没用。
it('should update items', () =>
expectSaga(sagas.changeItemsSaga, action)
.provide([
[select(prerequisite1), {}],
[select(prerequisite2), {}],
])
.put(actions.myAction1(payload1))
.put(actions.myAction2(payload2))
.run());它返回此错误。
Saga test error:
put expectation unmet:
Expected
--------
{ channel: null,
action:
{ type: 'MY_ACTION_1',
payload:
{ myItem1:
{ index: 0,
childItem1: [Object],
childItem2: [Object] } } } }
Actual:
------
1. { channel: null,
action:
{ type: 'MY_ACTION_1',
payload:
{ myItem1:
{ index: 0,
childItem1: [Object],
childItem2: [Object] } } } }
2. { channel: null,
action:
{ type: 'MY_ACTION_2',
payload: { itemCollection: [ [Object] ] } } }发布于 2020-04-23 22:48:51
provide语法允许您测试saga的最终效果,而不是引导所有状态。
下面是redux-saga文档的一个例子-
test('test only final effect with .provide()', () => {
/*
* With the .provide() method from expectSaga
* you can by pass in all expected values
* and test only your saga's final effect.
*/
return expectSaga(callApi, 'url')
.provide([
[select(selectFromState), selectedValue],
[call(myApi, 'url', selectedValue), response]
])
.put(success(response))
.run();
});通过调用actions调用2x,测试将连续运行,并有效地跳过sagas.changeItemsSaga中间的put。
看起来,您可能需要的函数是testSaga,它将使您更细粒度地洞察效果的流程。
https://stackoverflow.com/questions/61263046
复制相似问题