The saga has multiple puts.
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));
}
How do I write my put expectations when the saga is returning multiple effects?
it('should update items', () =>
expectSaga(sagas.changeItemsSaga, action)
.provide([
[select(prerequisite1), {}],
[select(prerequisite2), {}],
])
.put([actions.myAction1(payload1), actions.myAction2(payload2)])
.run());
ExpectSaga unit test returns the following error:
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] ] } } }
This one doesn't work either.
it('should update items', () =>
expectSaga(sagas.changeItemsSaga, action)
.provide([
[select(prerequisite1), {}],
[select(prerequisite2), {}],
])
.put(actions.myAction1(payload1))
.put(actions.myAction2(payload2))
.run());
It returns this error.
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] ] } } }