jfairbank / redux-saga-test-plan

Test Redux Saga with an easy plan.
http://redux-saga-test-plan.jeremyfairbank.com
MIT License
1.25k stars 127 forks source link

How to test self cancellation? #382

Open kodmigor opened 2 years ago

kodmigor commented 2 years ago

Hi, everyone!

I have a saga with infinity loop, where it takes an action and depending on action's payload yield self cancellation. How this case may be tested correctly?

function* sagaWorker() {
  while (true) {
    const action = yield take("ACTION");
    if (action.payload === "CANCEL") yield cancel();
  }
}
test(`test SELF_CANCELLATION`, () => {
  const actionInProgress = {payload: "IN_PROGRESS", type: "ACTION"};
  const actionCancel = {payload: "CANCEL", type: "ACTION"};
  testSaga(sagaWorker)
    .next()
    .take("ACTION")
    .next(actionInProgress)
    .take("ACTION")
    .next(actionCancel)
    // what must be here?
    .next()
    .isDone();
});