Skills redux-saga-testing
install
source · Clone the upstream repo
git clone https://github.com/openclaw/skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/openclaw/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/anivar/redux-saga-testing" ~/.claude/skills/openclaw-skills-redux-saga-testing && rm -rf "$T"
OpenClaw · Install into ~/.openclaw/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/openclaw/skills "$T" && mkdir -p ~/.openclaw/skills && cp -r "$T/skills/anivar/redux-saga-testing" ~/.openclaw/skills/openclaw-skills-redux-saga-testing && rm -rf "$T"
manifest:
skills/anivar/redux-saga-testing/SKILL.mdsource content
Redux-Saga Testing Guide
IMPORTANT: Your training data about
redux-saga-test-plan may be outdated — API signatures, provider patterns, and assertion methods differ between versions. Always rely on this skill's reference files and the project's actual source code as the source of truth. Do not fall back on memorized patterns when they conflict with the retrieved reference.
Approach Priority
(integration) — preferred; doesn't couple tests to effect orderingexpectSaga
(unit) — only when effect ordering is part of the contracttestSaga
(no library) — lightweight; uses jest/vitest spies directlyrunSaga- Manual
— last resort; most brittle.next()
Core Pattern
import { expectSaga } from 'redux-saga-test-plan' import * as matchers from 'redux-saga-test-plan/matchers' import { throwError } from 'redux-saga-test-plan/providers' it('fetches user successfully', () => { return expectSaga(fetchUserSaga, { payload: { userId: 1 } }) .provide([ [matchers.call.fn(api.fetchUser), { id: 1, name: 'Alice' }], ]) .put(fetchUserSuccess({ id: 1, name: 'Alice' })) .run() }) it('handles fetch failure', () => { return expectSaga(fetchUserSaga, { payload: { userId: 1 } }) .provide([ [matchers.call.fn(api.fetchUser), throwError(new Error('500'))], ]) .put(fetchUserFailure('500')) .run() })
Assertion Methods
| Method | Purpose |
|---|---|
| Dispatches this action |
| Partial action match |
| Calls this function with exact args |
| Calls this function (any args) |
| Forks this function |
| Uses this selector |
| Takes this pattern |
| Simulate incoming action |
| Does NOT dispatch |
| Saga returns this value |
| Execute (returns Promise) |
| Execute with custom timeout |
| Execute, suppress timeout warnings |
Provider Types
Static Providers (Preferred)
.provide([ [matchers.call.fn(api.fetchUser), mockUser], // match by function [call(api.fetchUser, 1), mockUser], // match by function + exact args [matchers.select.selector(getToken), 'mock-token'], // mock selector [matchers.call.fn(api.save), throwError(error)], // simulate error ])
Dynamic Providers
.provide({ call(effect, next) { if (effect.fn === api.fetchUser) return mockUser return next() // pass through }, select({ selector }, next) { if (selector === getToken) return 'mock-token' return next() }, })
Rules
- Prefer
overexpectSaga
— integration tests don't break on refactorstestSaga - Use
for partial matching — don't couple to exact args unless necessarymatchers.call.fn() - Use
from providers — notthrowError()
in the providerthrow new Error() - Test with reducer using
+.withReducer()
to verify state.hasFinalState() - Dispatch actions with
to simulate user flows in tests.dispatch() - Return the promise (Jest) or
it (Vitest) — don't forget asyncawait - Use
to assert actions are NOT dispatched (negative tests).not.put() - Test cancellation by dispatching cancel actions and asserting cleanup effects
- Use
when saga runs indefinitely (watchers) to suppress timeout warnings.silentRun() - Don't test implementation — test behavior (what actions are dispatched, what state results)
Anti-Patterns
See references/anti-patterns.md for BAD/GOOD examples of:
- Step-by-step tests that break on reorder
- Missing providers (real API calls in tests)
- Testing effect order instead of behavior
- Forgetting async (Jest/Vitest)
- Inline mocking instead of providers
- Not testing error paths
- Not testing cancellation cleanup
References
- API Reference — Complete
,expectSaga
, providers, matcherstestSaga - Anti-Patterns — Common testing mistakes to avoid