redux-saga-test-plan icon indicating copy to clipboard operation
redux-saga-test-plan copied to clipboard

v4.0.0-beta.1 run() resolved even though saga throw

Open dangh opened this issue 6 years ago • 3 comments

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

dangh avatar Aug 10 '18 05:08 dangh

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);

dangh avatar Aug 14 '18 07:08 dangh

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.

dabrowne avatar Aug 16 '18 21:08 dabrowne

In v4.0.0-beta.3 has the same problem

Justinidlerz avatar Aug 07 '19 07:08 Justinidlerz