react-testing-library

Apply React Testing Library best practices for user-centric tests.

2|1|Updated Apr 4, 2026
One-click install
npx skills add https://github.com/genfeedai/genfeed.ai --skill react-testing-library-genfeedai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-testing-library
Source: https://github.com/genfeedai/genfeed.ai/tree/main/.agents/skills/react-testing-library
Command: npx skills add https://github.com/genfeedai/genfeed.ai --skill react-testing-library-genfeedai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

This guide helps teams reduce flaky and brittle tests by establishing a robust set of React Testing Library (RTL) best practices that focus on user-visible behavior rather than implementation details.

Core Features & Use Cases

  • Guidance on selecting resilient, user-centric RTL queries (getByRole, getByLabelText, etc.) to test what users see.
  • Clear async handling patterns with findBy*, waitFor, and within() scoping to prevent false positives.
  • Anti-patterns and pragmatic testing patterns to improve reliability, readability, and accessibility coverage.
  • Practical use cases for writing new RTL tests, reviewing existing suites, and performing refactors to align with user behavior.

Quick Start

Consult this guide and start applying RTL best practices to your test suite.

Frequently Asked Questions about react-testing-library

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

FAQPage Schema
What are React Testing Library best practices for avoiding brittle tests?

React Testing Library best practices recommend using user-centric queries like getByRole to test visible behavior. This approach avoids querying implementation details, ensuring your tests remain resilient and accurately reflect user interactions.

How do I handle async operations in React Testing Library?

Handle async operations in React Testing Library using findBy queries, waitFor, and within scoping. These patterns properly wait for dynamic elements to appear, preventing false positives and flaky test failures.

Which RTL query should I use for accessibility testing?

Use getByRole and getByLabelText queries for accessibility testing in RTL. These queries prioritize how users interact with the UI, ensuring your tests validate accessible roles and visible labels rather than internal DOM structures.

How do I simulate user events in React Testing Library?

Simulate user events in React Testing Library using the user-event library. This provides realistic interaction simulation, ensuring tests validate actual user behavior rather than synthetic event dispatching.

Why are my React Testing Library tests flaky?

React Testing Library tests often become flaky due to querying implementation details or improper async handling. Refactoring to use resilient queries and waitFor patterns aligns tests with user behavior and reduces false positives.