react-testing-library

Generate React Testing Library tests that verify user-observable behavior and accessibility.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/moughamir/justwaitit-review --skill react-testing-library-moughamir
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-testing-library
Source: https://github.com/moughamir/justwaitit-review/tree/main/.agents/skills/react-testing-library
Command: npx skills add https://github.com/moughamir/justwaitit-review --skill react-testing-library-moughamir

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you avoid brittle, implementation-focused React Testing Library tests by guiding you toward maintainable, user-centric assertions and interactions that match how people actually use the UI.

Core Features & Use Cases

  • Query selection that reflects accessibility: Prefer role- and label-based queries to verify the accessibility tree and reduce order/structure brittleness.
  • Reliable async and interaction patterns: Use findBy, await userEvent, and keep waitFor focused on the right kind of waiting to prevent flaky or false-positive tests.
  • Common anti-pattern prevention: Avoid unnecessary act(), manual cleanup, container/querySelector querying, empty waitFor callbacks, and implementation details that break during refactors.
  • Structured, reviewable tests: Apply Arrange-Act-Assert, test one behavior per test, and use descriptive naming for faster failure diagnosis.

Quick Start

Use the react-testing-library skill to review or write a React component test by replacing getByTestId, fixing async handling with findBy/await, and rewriting assertions to use user-visible queries and jest-dom matchers.

Frequently Asked Questions about react-testing-library

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

FAQPage Schema
How do I write React Testing Library tests that don't break during refactoring?

Prefer role- and label-based accessibility queries over implementation details to write maintainable React Testing Library tests. This verifies user-observable behavior and keeps tests resilient to internal component refactoring.

What's the best way to handle async rendering and user interactions in React component tests?

Use findBy queries for asynchronously appearing elements and await userEvent for interactions to handle async rendering in React component tests. Keep waitFor focused on specific assertions to prevent flaky tests and avoid empty callbacks.

Why does my React Testing Library test throw unnecessary act warnings?

Unnecessary act warnings in React Testing Library occur from manual state updates or incorrect async handling. Use findBy queries and await userEvent async semantics to let the library handle updates, preventing unnecessary act wrappers.

Should I use container.querySelector in React Testing Library?

Avoid container.querySelector in React Testing Library as it bypasses the accessibility tree and tests implementation details. Use role- and label-based queries like getByRole to verify user-visible behavior and ensure components are accessible.

Can I use React Testing Library with Vitest and jest-dom matchers?

React Testing Library applies across Jest and Vitest-style setups. It works seamlessly with jest-dom matchers to assert user-observable behavior and accessibility, enabling structured Arrange-Act-Assert tests that diagnose failures quickly.