Helper for testing redux-saga
Switch branches/tags
Clone or download
Latest commit 18c0d49 Jan 16, 2017

redux-saga-test Build Status

A little helper to test [redux-saga][rs].


$ npm install --save-dev redux-saga-test


The saga under test.

function * testSaga () {
  try {
    yield put({type: 'FETCHING'})
    const data = yield call(loadData)
    yield put({type: 'FETCHED', payload: data})
  } catch (e) {
    yield put({type: 'FETCHED', payload: e})

The test looks like this:

const fromGenerator = require('redux-saga-test');

test('saga', (t) => {
  const expect = fromGenerator(t, testSaga()) // <= pass your assert library with a `deepEqual` method.{type: 'FETCHING'}){type: 'FETCHED', payload: mockData})

To test a watcher you can use expect.takeEvery/takeLatest.

The watcher:

function * watchEvery () {
  yield * takeEvery('TEST_ACTION', testSaga)

The test:

test('takeEvery', (t) => {
  const expect = fromGenerator(t, watchEvery())
  expect.takeEvery('TEST_ACTION', testSaga)

For more examples look at the tests


MIT © Stoeffel