mcpField
R
react-testing

react-testing

github.com/fusengineTesting & quality3442 installsUpdated 2w ago
Repository

About react-testing

A methodology skill for developers testing React 19 components with Testing Library and Vitest. It emphasizes user behavior and accessibility, and includes setup guidance and nine test templates.

Key features

  1. 01Prioritizes accessible queries
  2. 02Uses userEvent for interactions
  3. 03Uses findBy and waitFor for async tests
  4. 04Mocks APIs with MSW
  5. 05Covers React 19 and boundary tests
  6. 06Includes Vitest setup and nine templates

Use cases

  1. 01Verify component interactions
  2. 02Test custom hooks and React 19 features
  3. 03Audit accessibility and mock API calls

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/fusengine/agents --skill react-testing

After installing, type/react-testingin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
accessibility-testing.md
async-testing.md
hooks-testing.md
installation.md
mocking-patterns.md
msw-setup.md
queries.md
react-19-hooks.md
user-events.md
vitest-config.md
references/templates/
accessibility-audit.md
api-integration.md
basic-setup.md
component-async.md
component-basic.md
error-boundary.md
form-testing.md
hook-basic.md
suspense-testing.md

Details

From the project README
Tests React 19 components with Testing Library and Vitest: user-centric queries prioritized by accessibility (`getByRole` first, `getByTestId` last resort), `userEvent` for realistic interactions (never `fireEvent`), `findBy`/`waitFor` for async assertions (never `setTimeout`), and MSW for API mocking (never direct fetch mocking).

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:

  1. fuse-ai-pilot:explore-codebase - Analyze existing test patterns
  2. fuse-ai-pilot:research-expert - Verify latest Testing Library docs via Context7/Exa
  3. 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
FeatureBenefit
User-centricTests what users see
Accessible queriesEncourages a11y markup
No implementation detailsResilient to refactoring
Vitest integration10-20x faster than Jest

Critical Rules

  1. Query by role first - getByRole is most accessible
  2. Use userEvent, not fireEvent - Realistic interactions
  3. waitFor for async - Never setTimeout
  4. MSW for API mocking - Don't mock fetch
  5. Test behavior, not implementation - No internal state testing

Reference Guide

Concepts
TopicReference
Setup & installationreferences/installation.md
Query priorityreferences/queries.md
User interactionsreferences/user-events.md
Async patternsreferences/async-testing.md
API mockingreferences/msw-setup.md
React 19 hooksreferences/react-19-hooks.md
Accessibilityreferences/accessibility-testing.md
Custom hooksreferences/hooks-testing.md
Vitest configreferences/vitest-config.md
Mocking patternsreferences/mocking-patterns.md
Templates
TemplateUse Case
templates/basic-setup.mdVitest + RTL + MSW config
templates/component-basic.mdSimple component tests
templates/component-async.mdLoading/error/success
templates/form-testing.mdForms + useActionState
templates/hook-basic.mdCustom hook tests
templates/api-integration.mdMSW integration tests
templates/suspense-testing.mdSuspense + use()
templates/error-boundary.mdError boundary tests
templates/accessibility-audit.mdaxe-core a11y audit

Forbidden Patterns

PatternReasonAlternative
fireEventNot realisticuserEvent
setTimeoutFlakywaitFor, findBy
getByTestId firstNot accessiblegetByRole
Direct fetch mockingHard to maintainMSW
Empty waitForNo assertionAdd 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
  1. getByRole - Buttons, headings, inputs
  2. getByLabelText - Form inputs
  3. getByText - Static text
  4. getByTestId - 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

Comments

Markdown supported