testing

Guide React component, hook, and integration tests with Jest, React Testing Library, and MSW.

4|1|Updated Oct 13, 2025
One-click install
npx skills add https://github.com/buzzdan/ai-coding-rules --skill testing-buzzdan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/buzzdan/ai-coding-rules/tree/main/ts-react-linter-driven-development/skills/testing
Command: npx skills add https://github.com/buzzdan/ai-coding-rules --skill testing-buzzdan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Tests often focus on implementation details rather than user interactions, which can cause brittle tests that break with refactors.

Core Features & Use Cases

  • Emphasizes testing user behavior over internal state
  • Provides guidance for test structure, patterns, and strategy with Jest, React Testing Library, and MSW
  • Includes practical examples and best practices for leaf components and orchestrating tests

Quick Start

Use this guide to structure your tests around user interactions and accessibility, using real implementations and MSW to mock API calls.

Frequently Asked Questions about testing

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

FAQPage Schema
Why do my React tests break every time I refactor components?

React tests break during refactors when they assert on internal implementation details instead of user behavior. Testing by user interactions using accessible queries prevents brittle tests and keeps coverage stable across code changes.

How do I test React components using accessible queries and Jest?

Test React components by querying the DOM with accessible selectors like getByRole and getByLabelText in Jest. This validates user behavior and accessibility rather than testing internal state directly.

What is the best way to mock API calls in React integration tests?

Mock API calls in React integration tests using MSW to intercept network requests at the service worker level. This allows testing real implementations and async user behavior without modifying internal API logic.

Does React Testing Library work with TypeScript for hook and component tests?

React Testing Library works with TypeScript for hook and component tests, providing comprehensive coverage across leaf and orchestrating components by guiding test structure around real user interactions and waitFor-based async assertions.

When should I use waitFor for async assertions in React testing?

Use waitFor for async assertions in React testing when verifying user behavior involving asynchronous operations like API calls. waitFor waits for dynamic DOM updates before asserting, preventing flaky tests in integration scenarios.