1

Given a saga that operates over the action payload, where action has been passed in by takeLatest e.g.

export function* mySaga(action) {
  try {
    yield all(action.payload.items.map(p => call(doSomething, p)));
    }
    yield put(actionSuccess());
  } catch (error) {
    yield put(actionFailed(error));
  }
}

export function* watchMySaga() {
  yield takeLatest(AN_ACTION, mySaga);
}

how do I mock action in my redux-saga-test-plan test for mySaga? As action.payload is undefined, my test currently throws an error.

Bayard Randel
  • 9,930
  • 3
  • 42
  • 46

1 Answers1

1

So it appears, you simply pass a mock action object as the second argument to expectSaga, e.g.

return expectSaga(mySaga, action)
    .provide([[...]])
    .put(actionSuccess())
    .run();
Bayard Randel
  • 9,930
  • 3
  • 42
  • 46