react-testing

Tests React 19 components with Testing Library, Vitest, userEvent, and MSW.

1|Updated Jul 29, 2026
One-click install
npx skills add https://github.com/fusengine/kimi-code --skill react-testing-fusengine
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-testing
Source: https://github.com/fusengine/kimi-code/tree/main/plugins/react-expert/skills/react-testing
Command: npx skills add https://github.com/fusengine/kimi-code --skill react-testing-fusengine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires vitest, @testing-library/react, @testing-library/user-event, @testing-library/jest-dom, jsdom, msw, vitest-axe, and includes references (resource) components.

What problem does it solve? Writing reliable React component tests is hard: flaky async assertions, unrealistic event simulation, and brittle fetch mocking lead to test suites that break on refactors and miss real user-facing bugs. This Skill provides a complete testing methodology for React 19 components using Testing Library and Vitest, enforcing accessible queries, realistic interactions, and network-level API mocking. ## Core Features & Use Cases - User-Centric Testing Patterns: Prioritizes accessible queries (getByRole first, getByTestId last), uses userEvent instead of fireEvent, and findBy/waitFor instead of setTimeout for async assertions. - React 19 Feature Coverage: Test templates for useActionState forms, use() with Suspense boundaries, error boundaries, custom hooks via renderHook, and accessibility audits with axe-core. - MSW API Mocking: Network-level request interception with per-test handler overrides for loading, error, and success states. - Use Case: You need to test a login form built with React 19's useActionState. The Skill guides you to assert the pending disabled state, validation errors, and success message using userEvent and findByText, with MSW handling the server action responses. ## Quick Start Ask the AI to write a Vitest test for your React component using Testing Library with userEvent interactions and MSW API mocking.

Frequently Asked Questions about react-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test React components with Testing Library and Vitest?▼

Render the component with render(), query elements using getByRole for accessibility, and simulate interactions with userEvent.setup(). Assert outcomes with jest-dom matchers like toBeInTheDocument(). Vitest provides the runner with jsdom as the browser environment.

userEvent vs fireEvent in React Testing Library?▼

userEvent simulates full realistic interaction sequences including focus management and per-character typing, while fireEvent dispatches a single synthetic event. Always prefer userEvent with await, since every method is asynchronous.

How do I test async loading states in React components?▼

Assert the loading indicator first, then use findByText or waitFor to wait for the resolved content, and verify the loading state disappears. Never use setTimeout, which makes tests flaky.

How do I mock API calls in React tests with MSW?▼

MSW intercepts requests at the network level using handlers defined with http.get and HttpResponse.json. Override handlers per test with server.use() to simulate errors or slow networks, and reset them after each test with server.resetHandlers().

How do I test React 19 useActionState forms?▼

Submit the form with userEvent, assert the submit button is disabled during the pending state, then use findByText to verify the success or error message returned by the server action. Wrap async assertions in waitFor when checking multiple states.

When should I use renderHook instead of a component test?▼

Use renderHook for complex reusable hooks with isolated logic, providing a wrapper when the hook needs context providers. Prefer component tests for simple useState wrappers or hooks tightly coupled to a component.