Registry / testing / redux-saga-test-plan

redux-saga-test-plan

JSON →
library4.0.6jsnpmunverified

Redux Saga Test Plan is a JavaScript/TypeScript library designed to streamline the testing of Redux Sagas. Currently at version 4.0.6, it provides robust APIs for both integration and unit testing methodologies. The library allows developers to test sagas either by asserting the exact order and type of yielded effects (unit testing with `testSaga`, though not in this excerpt) or by focusing on the overall behavior and side effects, such as dispatched actions, when the saga runs with a mock Redux store (`expectSaga`). It features a chainable API and a powerful provider system for mocking dependencies like `call` effects, allowing for isolated and predictable tests. Releases for major versions are carefully planned, often preceded by release candidates, while minor and patch versions address bugs and introduce features within the stable major release. Key differentiators include its dual-approach to testing (unit and integration) and its comprehensive mocking capabilities via providers.

npm install redux-saga-test-plan
INSTALL
IMPORT
SIG · REDUX-SAGA-TEST-PL
R
redux-saga-test-plan
testingjavascriptv4.0.6
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

expectSaga
✓ import { expectSaga } from 'redux-saga-test-plan';
✗ const expectSaga = require('redux-saga-test-plan').expectSaga;
Primary named export for integration testing. CommonJS `require` is not officially supported and may lead to issues without proper transpilation.
testSaga
✓ import { testSaga } from 'redux-saga-test-plan';
✗ import testSaga from 'redux-saga-test-plan';
Named export for unit testing sagas. Do not use default import.
P (providers)
✓ import { call, select, put } from 'redux-saga-test-plan/providers';
✗ import { P } from 'redux-saga-test-plan';
Providers for mocking Redux Saga effects are imported from the 'redux-saga-test-plan/providers' subpath, not the main package entry point. The 'P' alias is a common convention for these providers.

Demonstrates an integration test for a Redux Saga using `expectSaga`, including effect assertions and dispatching actions within a test runner like Jest.

import { call, put, take } from 'redux-saga/effects'; import { expectSaga } from 'redux-saga-test-plan'; function* userSaga(api) { const action = yield take('REQUEST_USER'); const user = yield call(api.fetchUser, action.payload); yield put({ type: 'RECEIVE_USER', payload: user }); } it('just works!', () => { const api = { fetchUser: id => ({ id, name: 'Tucker' }), }; return expectSaga(userSaga, api) // Assert that the `put` will eventually happen. .put({ type: 'RECEIVE_USER', payload: { id: 42, name: 'Tucker' }, }) // Dispatch any actions that the saga will `take`. .dispatch({ type: 'REQUEST_USER', payload: 42 }) // Start the test. Returns a Promise. .run(); });
Debug
Known issues
breakingVersion 4.0.0 dropped support for Node.js versions under 8. Users on older Node.js environments must upgrade their Node.js runtime.
fix
Upgrade Node.js to version 8 or higher.
affects: >=4.0.0
breakingVersion 4.0.0 updated its internal Babel version to 7. This change might affect projects with specific Babel configurations or older Babel versions, potentially requiring adjustments to build processes.
fix
Review your project's Babel configuration and ensure compatibility with Babel 7. Upgrade other Babel-related dependencies if necessary.
affects: >=4.0.0
gotchaIntegration testing with `expectSaga` requires a global `Promise` object to be available in the environment. In environments lacking this, such as older browsers or specific test runners, a polyfill might be necessary.
fix
Ensure a global `Promise` polyfill (e.g., `core-js/es/promise`) is loaded before running tests if your environment does not provide one natively.
affects: >=1.0.0
gotchaTypeScript type definitions received significant fixes and updates in version 4.0.0 and subsequent RCs, particularly concerning compatibility with `redux-saga` v1.1.1. Users upgrading from pre-4.x versions may encounter type errors, especially if using older `redux-saga` versions or complex type inference.
fix
Ensure `redux-saga` is updated to a compatible version (e.g., ^1.1.1 or newer). Review and adjust any custom TypeScript types or interfaces that interact with `redux-saga-test-plan`'s APIs.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: expectSaga is not a function
Attempting to import `expectSaga` using CommonJS `require` without proper destructuring, or using a default import in ESM where a named import is expected.
fix
For ESM, use `import { expectSaga } from 'redux-saga-test-plan';`. For CommonJS (if transpiling or using older Node), ensure named destructuring: `const { expectSaga } = require('redux-saga-test-plan');`.
TS2307: Cannot find module 'redux-saga-test-plan' or its corresponding type declarations.
TypeScript compiler cannot locate the package's type definitions, possibly due to incorrect installation, `tsconfig.json` misconfiguration, or incompatible `redux-saga` peer dependency version.
fix
Verify `redux-saga-test-plan` is correctly installed. Ensure `tsconfig.json` has `moduleResolution` set to 'node' and that `redux-saga` (a peer dependency) is also installed and compatible with the installed `redux-saga-test-plan` version.
Saga test timed out. Saga did not complete within the allotted time.
The saga under test either entered an infinite loop, waited indefinitely for an action that was never dispatched, or encountered an unhandled error causing it to halt without resolution.
fix
Examine the saga's logic for potential infinite loops or missing `yield take` effects. Ensure all necessary actions are dispatched via `.dispatch()` in your test plan. Increase the timeout if the saga is genuinely long-running, but this often indicates a logical issue in the saga or test setup.
Upgrade
Version history
4.0.6latest on npm
Audit
Dependencies
redux-sagarequiredCore dependency for Redux Saga functionality
@redux-saga/isrequiredInternal Redux Saga utility
@redux-saga/symbolsrequiredInternal Redux Saga utility
Agent activity
3 hits · last 30 days
Resources
redux-saga-test-plan — npm install redux-saga-test-plan · libregistry