Socket
Book a DemoInstallSign in
Socket

redux-saga-test

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-saga-test

My finest module

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
53
-38.37%
Maintainers
2
Weekly downloads
 
Created
Source

redux-saga-test Build Status

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

Install

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

Usage

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.

  expect.next().put({type: 'FETCHING'})
  expect.next().call(loadData)
  expect.next(mockData).put({type: 'FETCHED', payload: mockData})
  expect.next().returns()
})

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

License

MIT © Stoeffel

Keywords

redux

FAQs

Package last updated on 16 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts