jfairbank / redux-saga-test-plan

Test Redux Saga with an easy plan.
http://redux-saga-test-plan.jeremyfairbank.com
MIT License
1.25k stars 127 forks source link

Throwing an exception out of a saga sometimes does not make test fail #192

Open fkruegel opened 6 years ago

fkruegel commented 6 years ago

Tests should fail when they throw an exception. However, in the following test

import { call } from 'redux-saga/effects';
import { expectSaga } from 'redux-saga-test-plan';

const someFunction = function () {
    return 'someValue';
}

function* someSaga() {
    throw(new Error('An error'));
    const returnValue = yield call(someFunction);
    console.log(returnValue);
}

function* otherSaga() {
    const returnValue = yield call(someFunction);
    console.log(returnValue);
    throw(new Error('An error'));
}

it('fails', () => {
    return expectSaga(someSaga)
        .run();
});

it('succeeds, but should fail', () => {
    return expectSaga(otherSaga)
        .run();
});

only the first test fails as expected, whereas the second test (where the exception is thrown after the first yield instead of before) succeeds. This behavior does not seem to be intended. I'm using redux-saga 0.16.0 and redux-saga-test-plan 3.6.0.

xli1000 commented 6 years ago

It seems that expectSaga returns a promise, which is rejected when there is an exception in the saga.

So

await expectSaga(otherSaga)
  .run();

fails, as does:

expectSaga(otherSaga)
  .catch((e) => fail(e))
  .run();
ACoolmanBigHealth commented 5 years ago

@xli1000 What is fail in catch((e) => fail(e))?