react-testing
БесплатноБез исполняемых скриптовНе проверенTesting Library for React 19 - render, screen, userEvent, waitFor, Suspense. Use when writing tests for React components with Vitest.
от Fusengine★ 36 звёзд на GitHubОб этом скилле
Also covers testing React 19 features (useActionState, use()), custom hooks, Suspense boundaries, error boundaries, and accessibility audits with axe-core. Provides Vitest configuration and 9 ready-to-copy test templates. This is a testing-methodology skill layered on top of the React skills (react-19, react-state, react-forms) — it doesn't teach those APIs themselves, only how to test components that use them.
React Testing Library
Test React components the way users interact with them.
Agent Workflow (MANDATORY)
Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:
- fuse-ai-pilot:explore-codebase - Analyze existing test patterns
- fuse-ai-pilot:research-expert - Verify latest Testing Library docs via Context7/Exa
- mcp__context7__query-docs - Check userEvent, waitFor patterns
After implementation, run fuse-ai-pilot:sniper for validation.
Overview
When to Use
- Testing React component behavior
- Validating user interactions
- Ensuring accessibility compliance
- Mocking API calls with MSW
- Testing custom hooks
- Testing React 19 features (useActionState, use())
Why React Testing Library
| Feature | Benefit |
|---|---|
| User-centric | Tests what users see |
| Accessible queries | Encourages a11y markup |
| No implementation details | Resilient to refactoring |
| Vitest integration | 10-20x faster than Jest |
Critical Rules
- Query by role first -
getByRoleis most accessible - Use userEvent, not fireEvent - Realistic interactions
- waitFor for async - Never
setTimeout - MSW for API mocking - Don't mock fetch
- Test behavior, not implementation - No internal state testing
Reference Guide
Concepts
| Topic | Reference |
|---|---|
| Setup & installation | references/installation.md |
| Query priority | references/queries.md |
| User interactions | references/user-events.md |
| Async patterns | references/async-testing.md |
| API mocking | references/msw-setup.md |
| React 19 hooks | references/react-19-hooks.md |
| Accessibility | references/accessibility-testing.md |
| Custom hooks | references/hooks-testing.md |
| Vitest config | references/vitest-config.md |
| Mocking patterns | references/mocking-patterns.md |
Templates
| Template | Use Case |
|---|---|
templates/basic-setup.md |
Vitest + RTL + MSW config |
templates/component-basic.md |
Simple component tests |
templates/component-async.md |
Loading/error/success |
templates/form-testing.md |
Forms + useActionState |
templates/hook-basic.md |
Custom hook tests |
templates/api-integration.md |
MSW integration tests |
templates/suspense-testing.md |
Suspense + use() |
templates/error-boundary.md |
Error boundary tests |
templates/accessibility-audit.md |
axe-core a11y audit |
Forbidden Patterns
| Pattern | Reason | Alternative |
|---|---|---|
fireEvent |
Not realistic | userEvent |
setTimeout |
Flaky | waitFor, findBy |
getByTestId first |
Not accessible | getByRole |
| Direct fetch mocking | Hard to maintain | MSW |
Empty waitFor |
No assertion | Add expect() |
Quick Start
Install
npm install -D vitest @testing-library/react \
@testing-library/user-event @testing-library/jest-dom \
jsdom msw
→ See templates/basic-setup.md for complete configuration
Basic Test
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
test('button click works', async () => {
const user = userEvent.setup()
render(<Button onClick={fn}>Click</Button>)
await user.click(screen.getByRole('button'))
expect(fn).toHaveBeenCalled()
})
→ See templates/component-basic.md for more examples
Best Practices
Query Priority
getByRole- Buttons, headings, inputsgetByLabelText- Form inputsgetByText- Static textgetByTestId- Last resort
Async Pattern
// Preferred: findBy
await screen.findByText('Loaded')
// Alternative: waitFor
await waitFor(() => expect(...).toBeInTheDocument())
→ See templates/component-async.md
userEvent Setup
const user = userEvent.setup()
await user.click(button)
await user.type(input, 'text')
→ See references/user-events.md
Установить react-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл react-testing?
Testing Library for React 19 - render, screen, userEvent, waitFor, Suspense. Use when writing tests for React components with Vitest.
Как установить скилл react-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл react-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic