redux-saga-test-plan
redux-saga-test-plan copied to clipboard
v4.0.0-beta.1 run() resolved even though saga throw
In redux-saga-test-plan
v3.7.0
and redux-saga
v0.16.0
, I used to test exception in saga as below:
let saga = function* () {
throw new Error('fail')
}
expect.assertions(1)
expectSaga(saga)
.run()
.catch(err => {
expect(err.message).toBe('fail')
})
but it's not working anymore in v4.0.0-beta.1
and redux-saga
v1.0.0-beta.1
Actually it's not just 4.0.0-beta.1
The error is throw here outside of redux-saga so it never been caught
https://github.com/jfairbank/redux-saga-test-plan/blob/7f78a0742f94c67a221a9a1370b65f65e38b66b6/src/expectSaga/sagaWrapper.js#L42
Below is my patch:
- let result = wrappedIterator.next();
+ let result;
+ let started = false;
return fsmIterator(INIT, {
[INIT](_, fsm) {
try {
+ if (!started) {
+ started = true;
+ result = wrappedIterator.next();
+ }
+
if (result.done) {
return complete();
}
let value = refineYieldedValue(result.value);
I have also fixed this as part of https://github.com/jfairbank/redux-saga-test-plan/pull/212
See changes to sagaWrapper.js:
https://github.com/jfairbank/redux-saga-test-plan/pull/212/files?utf8=%E2%9C%93&diff=unified#diff-cc0aab9e3239aed33eb791275ac982ea
Maybe make some noise if you'd like it merged as I've had no response so far.
In v4.0.0-beta.3
has the same problem