搜索

PythonReactSEOPDF
OpenClaw

redux-saga-testing

Write tests for Redux Sagas using redux-saga-test-plan, runSaga, and manual generator testing. Covers expectSaga (integration), testSaga (unit), providers, partial matchers, reducer integration, error simulation, and cancellation testing. Works with Jest and Vitest. Triggers on: test files for sagas, redux-saga-test-plan imports, mentions of "test saga", "saga test", "expectSaga", "testSaga", or "redux-saga-test-plan".

anivar0 来源安装数☆ 0 仓库 Stars

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

SkillHub CLI

skillhub install anivar/redux-saga-testing

打开来源仓库,查看说明和兼容环境后,按来源提供的命令或步骤安装。

将来源链接提供给你的 Agent,让它先读取说明、核对依赖,并向你说明将执行的安装步骤。

查看来源 ↗使用指南

技能说明

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

  1. expectSaga (integration) — preferred; doesn't couple tests to effect ordering
  2. testSaga (unit) — only when effect ordering is part of the contract
  3. runSaga (no library) — lightweight; uses jest/vitest spies directly
  4. Manual .next() — last resort; most brittle

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
.put(action) Dispatches this action
.put.like({ action: { type } }) Partial action match
.call(fn, ...args) Calls this function with exact args
.call.fn(fn) Calls this function (any args)
.fork(fn, ...args) Forks this function
.select(selector) Uses this selector
.take(pattern) Takes this pattern
.dispatch(action) Simulate incoming action
.not.put(action) Does NOT dispatch
.returns(value) Saga returns this value
.run() Execute (returns Prom...

来源信息

Source
github
Repository
openclaw/skills
Path
skills/anivar/redux-saga-testing
Version
—
Commit
f127763c2e01270c4bbb33bbfd397345ac41da5c
分类来源
rules
状态
active
可见性
public

这些信息来自收录时的来源分析,可能滞后;使用前请核对最新来源文件。

README

Redux-Saga Testing

Created by Anivar Aravind

An AI agent skill for writing tests for Redux Sagas using redux-saga-test-plan. Works with Jest and Vitest.

The Problem

AI agents often write saga tests that are brittle (asserting exact effect order when it doesn't matter), miss provider setup (causing tests to hit real APIs), or use manual generator stepping when expectSaga would be simpler and more maintainable. The result: tests that break on harmless refactors and pass when they shouldn't.

This Solution

A focused testing skill covering expectSaga (integration), testSaga (unit), providers, matchers, and reducer integration — with 12 anti-patterns showing exactly what goes wrong and how to fix it.

Install

npx skills add anivar/redux-saga-testing -g

Or with full URL:

npx skills add https://github.com/anivar/redux-saga-testing

Baseline

  • redux-saga-test-plan ^5.x
  • redux-saga ^1.4.2
  • Jest or Vitest

What's Inside

Testing Approaches
Approach Type Use When
expectSaga Integration Default choice — order-independent, async, assertions on effects and state
testSaga Unit Effect ordering matters (e.g., must select before call)
runSaga Manual Need full store integration or custom middleware
Providers
Provider Type Purpose
Static providers Map effect → return value (simple, covers most cases)
Dynamic providers Custom logic per effect type (conditional mocking)
Partial matchers matchers.call.fn(apiFn) — match by function regardless of args
Anti-Patterns

12 common testing mistakes with BAD/GOOD code examples:

  • Asserting effect order in integration tests
  • Missing providers for API calls
  • Not awaiting expectSaga (test always passes)
  • Testing implementation instead of behavior
  • Ignoring error paths and cancellation

Structure

├── SKILL.md...

来源内容

SKILL.md
# 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

1. **`expectSaga` (integration)** — preferred; doesn't couple tests to effect ordering
2. **`testSaga` (unit)** — only when effect ordering is part of the contract
3. **`runSaga` (no library)** — lightweight; uses jest/vitest spies directly
4. **Manual `.next()`** — last resort; most brittle

## Core Pattern

```javascript
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 |
|--------|---------|
| `.put(action)` | Dispatches this action |
| `.put.like({ action: { type } })` | Partial action match |
| `.call(fn, ...args)` | Calls this function with exact args |
| `.call.fn(fn)` | Calls this function (any args) |
| `.fork(fn, ...args)` | Forks this function |
| `.select(selector)` | Uses this selector |
| `.take(pattern)` | Takes this pattern |
| `.dispatch(action)` | Simulate incoming action |
| `.not.put(action)` | Does NOT dispatch |
| `.returns(value)` | Saga returns this value |
| `.run()` | Execute (returns Prom...
README
# Redux-Saga Testing

Created by **[Anivar Aravind](https://anivar.net)**

An AI agent skill for writing tests for Redux Sagas using redux-saga-test-plan. Works with Jest and Vitest.

## The Problem

AI agents often write saga tests that are brittle (asserting exact effect order when it doesn't matter), miss provider setup (causing tests to hit real APIs), or use manual generator stepping when `expectSaga` would be simpler and more maintainable. The result: tests that break on harmless refactors and pass when they shouldn't.

## This Solution

A focused testing skill covering `expectSaga` (integration), `testSaga` (unit), providers, matchers, and reducer integration — with 12 anti-patterns showing exactly what goes wrong and how to fix it.

## Install

```bash
npx skills add anivar/redux-saga-testing -g
```

Or with full URL:

```bash
npx skills add https://github.com/anivar/redux-saga-testing
```

## Baseline

- redux-saga-test-plan ^5.x
- redux-saga ^1.4.2
- Jest or Vitest

## What's Inside

### Testing Approaches

| Approach | Type | Use When |
|----------|------|----------|
| `expectSaga` | Integration | Default choice — order-independent, async, assertions on effects and state |
| `testSaga` | Unit | Effect ordering matters (e.g., must `select` before `call`) |
| `runSaga` | Manual | Need full store integration or custom middleware |

### Providers

| Provider Type | Purpose |
|---------------|---------|
| Static providers | Map effect → return value (simple, covers most cases) |
| Dynamic providers | Custom logic per effect type (conditional mocking) |
| Partial matchers | `matchers.call.fn(apiFn)` — match by function regardless of args |

### Anti-Patterns

12 common testing mistakes with BAD/GOOD code examples:
- Asserting effect order in integration tests
- Missing providers for API calls
- Not awaiting `expectSaga` (test always passes)
- Testing implementation instead of behavior
- Ignoring error paths and cancellation

## Structure

```
├── SKILL.md...

相关技能

OpenClaw

bambu-studio-ai

heyixuan2

Bambu Lab 3D printer control and automation. Activate when user mentions: printer status, 3D printing, slice, analyze model, generate 3D, AMS filament, print monitor, Bambu Lab, or any 3D printing task. Full pi...

OpenClaw

geo-optimization

capt-marbles

Generative Engine Optimization (GEO) for AI search visibility. Optimize content to appear in ChatGPT, Perplexity, Claude, and Google AI Overviews. Use when optimizing websites, pages, or content for LLM discove...

OpenClaw

parakeet-stt

carlulsoe

Local speech-to-text with NVIDIA Parakeet TDT 0.6B v3 (ONNX on CPU). 30x faster than Whisper, 25 languages, auto-detection, OpenAI-compatible API. Use when transcribing audio files, converting speech to text, o...

OpenClaw

feishu-process-feedback

carlzhao007

飞书消息自动处理与进度反馈技能。安装后后台运行,监听飞书任务消息并自动创建独立进程处理。 在处理前后发送实时进度反馈(任务确认、进度百分比、完成通知)。 支持任务类型识别、智能解析、错误重试、并发控制、状态持久化...