frontend-testing

A testing guide for React components, hooks, and stores using Testing Library, Vitest, and Storybook. It explains how to test what users can observe and when to replace outside services with test substitutes.

In plain words
What is it for?
Use it when writing or refactoring frontend tests, testing hooks or stores, isolating child components, and choosing between test doubles.
Why use it?
It helps developers choose suitable tests and test substitutes without depending unnecessarily on implementation details or difficult external systems.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/recca0120/code-quest/frontend-testing
Any agent
npx skills add recca0120/code-quest --skill frontend-testing
Clone the repo
git clone --depth 1 https://github.com/recca0120/code-quest

Made for: Claude Code, Codex.

Per session 101 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,335 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00101 $0.03335
Opus 5 $0.00051 $0.01667
Sonnet 5 $0.00020 $0.00667
Haiku 4.5 $0.00010 $0.00333

Measured 3d ago against content hash eed344ec06e1, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

frontend-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/frontend-testing/SKILL.md · 251 lines

How it starts

The opening of the file, as written. The whole thing — 251 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Frontend Testing Guide

相關 skill 分工:

  • 五型經典定義(Dummy/Stub/Fake/Spy/Mock)→ test-doubles
  • Server 測試 pattern(DB / socket.io server-side)→ vitest-testing (server)
  • TDD 流程 → tdd-guidelines
  • Socket + pipeline test harness → fake-summoner-client
  • Hook / Context 慣例 → react-hooks
  • Storybook play function / 視覺回歸 → storybook-component
  • 共通慣例(RTL query、userEvent)→ testing-best-practices

Core Principles

這六條依序優先,後條在前條同時成立時才考慮。

1. Testing Library first; no unit/integration split

使用者視角撰寫測試,render 有意義的最小 tree;只有一種檔名 *.test.ts / *.test.tsx,不再有 *.integration.test.* 或其他變體。

  • ✅ 用 render() + testing-library query,不用 shallow render
  • ✅ 斷言使用者可觀察到的結果(DOM、callback、store 狀態),不斷言實作細節
  • ❌ 不在 vitest.config.ts 區分 unit / integration glob

2. Fake first — when the real external dependency is hard to use in tests

當測試對象依賴「外部系統」(網路、Socket.IO、瀏覽器 API、時間、CLI)且真實依賴不易在測試中使用時,Fake 是首選替代品。對「內部 module」的觀察仍用 Spy;完全替換整個內部 module(vi.mock)是最後手段。

決策流程見 Test Double Decision Flow

3. Fake Component for subcomponent isolation

隔離子元件(不想連動其 deps)時,MUST 撰寫 Fake<Name> React 元件共用原 prop 型別,勝過 vi.mock('./X', () => ({ X: () => null }))

// ❌ BAD — 失去型別檢查,重構脆弱
vi.mock('./ComposeToolbar', () => ({ ComposeToolbar: () => null }));

// ✅ GOOD — Fake Component 契約對齊
// src/test/fake-compose-toolbar.tsx
import type { ComposeToolbarProps } from '../components/ComposeToolbar';

export function FakeComposeToolbar(props: ComposeToolbarProps) {
  return <div data-testid="fake-toolbar" data-mode={props.mode} />;
}

// test
vi.mock('./ComposeToolbar', () => ({ ComposeToolbar: FakeComposeToolbar }));
// 或 test helper 透過 props 注入

好處:

  • 維持 prop 型別檢查(重構 real component 時,fake 編譯錯誤提醒更新)
  • data-testid 斷言 parent 傳進去的 prop
  • 明確可見「這是測試替身」

4. Tests live at the smallest meaningful render root

用 testing-library 時,測試 render 的是對使用者有意義的最小單位,不是對原始碼檔案一檔對一檔。

情境 要不要建專屬 .test
純 util / store / hook ✅ 建(.test.ts / renderHook
有自身邏輯 / state / 複雜渲染的元件(如 EffortSwitch ✅ 建
簡單 presentational primitive(Badge / IconButton / PaletteEmpty) ❌ 不建;透過 consumer 測試覆蓋
Context / Provider ✅ 建(測 provider 本身),但簡單 state passthrough 可由 consumer 覆蓋

Read the full file on GitHub · 251 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 251 lines · 101 tokens per session scan A eed344ec06e1

Subscribe to this mod's changes

frontend-testing is a skill published in the GitHub repository recca0120/code-quest (11 stars, last pushed 2mo ago), licensed MIT. It adds 101 tokens to every session and 3,335 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

vitest

Vitest unit testing patterns with React Testing Library. Trigger: When writing unit tests for React components, hooks, or utilities.

prowler-cloud/prowler · 28 tokens

frontend-testing

Generate Vitest + React Testing Library tests for Dify frontend components, hooks, and utilities. Triggers on testing, spec files, coverage, Vitest, RTL, unit tests, integration tests, or write/review test requests.

Ohh-889/skyroc · 50 tokens

frontend-testing

Use when writing or changing Vitest or React Testing Library tests under web/ or packages/dify-ui/, or when the user explicitly requests frontend test strategy, including evaluation of an existing strategy. Do not use for frontend code-review-only requests, general testability discussion, Python tests, or…

langgenius/dify · 73 tokens

react-testing

Write and review React/TypeScript tests for Sentry's frontend using Jest and React Testing Library. Use when adding or editing tests in static/ (.spec.tsx), writing component/hook tests, mocking API responses with MockApiClient, testing routing or network requests, or when asked to "write a frontend test", "add a…

getsentry/sentry · 86 tokens

playground-msw-tests

REQUIRED and PRIMARY testing approach for packages/playground and packages/playground-ui. Triggers on: adding or modifying hooks, pages, route components, data-fetching code, React Query interactions, or any test work in these packages. Generates Vitest tests that drive the real @mastra/client-js + React Query stack…

mastra-ai/mastra · 121 tokens

unit-tests

Jest + React Testing Library best practices for Wonder Blocks unit tests. Use when creating or editing .test.ts / .test.tsx files.

Khan/wonder-blocks · 34 tokens