传奇有多个看跌期权。
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] ] } } }
provide
语法使您可以测试传奇的最终效果,而不用引导所有状态。
这里是redux-saga docs-的示例]
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,测试连续运行,并且put
中间的sagas.changeItemsSaga
有效地被跳过。
似乎您可能需要的功能是testSaga,它将使您更深入地了解效果的流程。