If I have a saga with this form:
function * sagaWorker() {
yield put(START_ACTION)
yield take(WAIT_FOR_ACTION)
yield delay(100)
yield put(END_ACTION)
}
I can successfully test it using runSaga
like this:
step('saga passes the tests', async () => {
const channel = stdChannel()
const dispatched = []
const options = {
dispatch: action => dispatched.push(action),
getState: () => {},
channel
}
const task = runSaga(options, sagaWorker)
channel.put(WAIT_FOR_ACTION)
await task.toPromise()
expect(dispatched).to.deep.eql([START_ACTION, END_ACTION])
})
However, if I move the delay in front of the take:
function * sagaWorker() {
yield put(START_ACTION)
yield delay(100)
yield take(WAIT_FOR_ACTION)
yield put(END_ACTION)
}
Now the saga doesn't run to completion and times out - it gets to the take
but the action never arrives in the channel.
Is it possible to test it using this form? I suspect I can make it work by call
ing the delay
s rather than yield
ing them directly but I'd like to know how to make it work without doing that (if it's possible).