React testing
Skill fusengine/agents/plugins/react-expert/skills/react-testing
Redefining development through cognitive automation and collaborative agent systems.
npx -y skills add fusengine/agents --skill react-testingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 22 stars22 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Testing Library for React 19 - render, screen, userEvent, waitFor, Suspense. Use when writing tests for React components with Vitest.
SKILL.md
4.9 KB, 979 tokens by cl100k_base, as published. Nobody here has run it
React Testing Library
Test React components the way users interact with them.
Agent Workflow (MANDATORY)
Before ANY implementation, use TeamCreate to spawn 3 agents:
- 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
What ships with it: 19 files
48.2 KB alongside SKILL.md
references/
- accessibility-testing.md1.6 KB
- async-testing.md1.4 KB
- hooks-testing.md1.4 KB
- installation.md1.5 KB
- mocking-patterns.md1.6 KB
- msw-setup.md1.6 KB
- queries.md1.5 KB
- react-19-hooks.md1.7 KB
- templates/accessibility-audit.md4.4 KB
- templates/api-integration.md4.2 KB
- templates/basic-setup.md2.6 KB
- templates/component-async.md3.5 KB
- templates/component-basic.md3.3 KB
- templates/error-boundary.md3.6 KB
- templates/form-testing.md4.1 KB
- templates/hook-basic.md3.8 KB
- templates/suspense-testing.md3.7 KB
- user-events.md1.4 KB
- vitest-config.md1.3 KB