redux-saga-test-plan
redux-saga-test-plan copied to clipboard
Using takeEvery from redux-saga/effects causes TypeError: Cannot read property 'next' of undefined
In the latest version of redux saga (^0.16.0) I was getting a console warning about how importing takeEvery from redux-saga was deprecated and that it needed to be from redux-saga/effects.
Doing so seems to have broken rstp, and now I get the following error:
console.error node_modules/redux-saga/lib/internal/utils.js:240
uncaught at tokenSaga at tokenSaga
at takeEvery
TypeError: Cannot read property 'next' of undefinedat sagaWrapper ([...]redux-saga-test-plan/lib/expectSaga/sagaWrapper.js:54:34)
switching back to the root takeEvery import works without a problem. Also worth noting that the sagas work fine outside of the test scenario.
Hi @mattoni.
The docs have a section on saga helpers. When you switch to redux-saga/effects for takeEvery, you'll need to update your tests to use takeEveryEffect. You also need to make sure you call next before takeEveryEffect like you have to do with other effects such as put.
Thanks for the response, I must have missed that in the docs. Is there no way to test takeEvery with expectSaga? That's what I was using when the error occurred.
Ah, sorry. I didn't pay enough attention to your error message to realize you were using expectSaga.
You don't need anything special for takeEvery. expectSaga runs your saga like redux-saga, so you can dispatch actions to the "inner" saga that takeEvery forks. See this example from the docs.
Does that help?
@jfairbank When I was testing sagas with effect "fork", I have errors like:
- 'Cannot read property 'next' of undefined'
- 'Cannot read property 'apply' of undefined'
And I guess that all this errors exist, because 'redux-saga-test-plan' calls function in effect 'fork' incorrectly. I solved this problem with
await expectSaga(myExampleSaga) .provide({ fork: effect => effect.fn(effect.args[0]), }) .run();
If I use this way, 'redux-saga-test-plan' calls function in effect 'fork' correctly.
If I don't want 'redux-saga-test-plan' calls function in effect 'fork', I use this second way (see below):
` await expectSaga(myExampleSaga)
.provide({
fork: (effect, next) => next,
})`
my package.json:
"redux-saga-test-plan": "4.0.0-rc.3",
"redux-saga": "^1.1.3",
Thank you for your wonderful library)
@jfairbank Addition:
if called function in effect 'fork' has one argument
await expectSaga(myExampleSaga) .provide({ fork: effect => effect.fn(effect.args[0]), }) .run();
if called function in effect 'fork' has two arguments
await expectSaga(myExampleSaga) .provide({ fork: effect => effect.fn(effect.args[0], effect.args[1]), }) .run();
etc