plugins/react-expert/skills/react-testing/SKILL.md
Testing Library for React 19 - render, screen, userEvent, waitFor, Suspense. Use when writing tests for React components with Vitest.
npx skillsauth add fusengine/agents react-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Test React components the way users interact with them.
Before ANY implementation, use TeamCreate to spawn 3 agents:
After implementation, run fuse-ai-pilot:sniper for validation.
| 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 |
getByRole is most accessiblesetTimeout| 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 |
| 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 |
| 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() |
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
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
getByRole - Buttons, headings, inputsgetByLabelText - Form inputsgetByText - Static textgetByTestId - Last resort// Preferred: findBy
await screen.findByText('Loaded')
// Alternative: waitFor
await waitFor(() => expect(...).toBeInTheDocument())
→ See templates/component-async.md
const user = userEvent.setup()
await user.click(button)
await user.type(input, 'text')
→ See references/user-events.md
testing
Copy self-audit and ban-lists — filler verbs/hype adjectives, slop placeholder names, fake-precise numbers, Title Case headlines, humor in error copy ('Oops!'), em-dash crutch, one copy register per page.
development
Logged-in web apps — dashboards, auth flows, settings, onboarding, data tables, command palettes, modals, toasts. Register `product`: density and glance-speed over marketing polish, no hero/CTA-tricks, every data surface covers empty/loading/error explicitly, tables and dataviz follow preattentive-processing rules.
development
Marketing sites, landing pages, campaign pages — register `brand` (design IS the product). Structure comes from the register's POV + a macrostructure pick, never from copying an inspiration site's section flow. Hero discipline, deviated section order, asymmetric grids, and a silhouette lookalike-test gate before ship.
development
Token-strategy core — OKLCH color rules, neutral tinting, accent-commitment levels, type scale, 8pt spacing grid, touch targets, and the canonical output format of design-system.md (the file the harness gates on). This is routing step 1 of design-method/SKILL.md — read it before design-web/design-webapp/design-ios/design-android, before picking or auditing a single color/type/spacing value.