Testing redux saga with a while loop and delay with redux-saga-test-plan

Viewed 319

I have a saga that delays increments a progress from 0 to 100 over 2 seconds. After 2 seconds, the saga will dispatch an action to submit an error. I am at a loss on how to test this using redux-saga-test-plan.

import { put, delay, takeLatest } from "redux-saga/effects";
import { incrementProgress } from "../actions/progress";
import { SUBMIT_ORDER_ERROR } from "../actions/orders";
import { receiveError } from "../actions/errors";

const TOTAL_DELAY = 2000;
const INTERVAL = 200;
let progress = 0;

export function* processErrorOrder() {
    while (progress <= 100) {
        yield delay(INTERVAL);
        progress += TOTAL_DELAY / INTERVAL;
        yield put(incrementProgress(progress));
    }
    if (progress >= 100) {
        yield put(receiveError("Order time has elapsed"));
    }
    if (progress > 100) {
        yield delay(1200);
        progress = 0;
        yield put(incrementProgress(progress));
    }
}
0 Answers
Related