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

withReducer doesn't dispatch actions to the reducer #335

Open MarcNq opened 4 years ago

MarcNq commented 4 years ago

Hi guys,

When testing the integration between a saga and a reducer, sometimes one needs to dispatch actions that affect the reducer in order to change the state in intermediate steps, but which the saga must completely ignore.

Such actions are being lost unless the saga takes them or puts them:

const {expectSaga} = require('redux-saga-test-plan')

function* a() {
  yield 'I do not take any action, but the reducer should handle them anyway'
}

function reducer(state = 0, action) {
  return action.value
}

expectSaga(a)
  .withReducer(reducer)
  .dispatch({type: 'A', value: 1})
  .hasFinalState(1)
  .run()

Outputs exception saying final state is undefined, when it should be 1.

Thank you for your help.