Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-saga-test-plan

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-saga-test-plan

Test Redux Saga with an easy plan

  • 4.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
165K
increased by18.13%
Maintainers
2
Weekly downloads
 
Created

What is redux-saga-test-plan?

redux-saga-test-plan is a testing utility for redux-saga, which allows you to test your sagas in a more declarative and less boilerplate-heavy way. It provides tools to test the effects and the flow of your sagas, making it easier to ensure that your asynchronous logic behaves as expected.

What are redux-saga-test-plan's main functionalities?

Unit Testing Sagas

This feature allows you to unit test individual sagas by asserting that certain effects (like call, put, etc.) are yielded. The example demonstrates testing a saga that calls an API and returns the response.

const { expectSaga } = require('redux-saga-test-plan');
const { call } = require('redux-saga/effects');

function* fetchData(api) {
  const response = yield call(api);
  return response;
}

expectSaga(fetchData, api)
  .call(api)
  .returns({ data: 'test' })
  .run();

Integration Testing Sagas

This feature allows you to perform integration tests by running the saga with a reducer and asserting the final state. The example shows testing a saga that fetches data and updates the state based on the result.

const { expectSaga } = require('redux-saga-test-plan');
const { call, put } = require('redux-saga/effects');
const { combineReducers } = require('redux');

function* fetchData(api) {
  try {
    const response = yield call(api);
    yield put({ type: 'FETCH_SUCCESS', payload: response });
  } catch (error) {
    yield put({ type: 'FETCH_FAILURE', error });
  }
}

const reducer = combineReducers({
  data: (state = null, action) => {
    switch (action.type) {
      case 'FETCH_SUCCESS':
        return action.payload;
      default:
        return state;
    }
  }
});

expectSaga(fetchData, api)
  .withReducer(reducer)
  .provide([[call(api), { data: 'test' }]])
  .hasFinalState({ data: { data: 'test' } })
  .run();

Mocking Effects

This feature allows you to mock the effects that your saga yields, making it easier to test sagas in isolation. The example demonstrates mocking an API call within a saga.

const { expectSaga } = require('redux-saga-test-plan');
const { call } = require('redux-saga/effects');

function* fetchData(api) {
  const response = yield call(api);
  return response;
}

expectSaga(fetchData, api)
  .provide([[call(api), { data: 'mocked' }]])
  .returns({ data: 'mocked' })
  .run();

Other packages similar to redux-saga-test-plan

Keywords

FAQs

Package last updated on 05 Sep 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc