Agent Skills: React Testing Library Best Practices

React Testing Library best practices for writing maintainable, user-centric tests. Use when writing, reviewing, or refactoring RTL tests. Triggers on test files, testing patterns, getBy/queryBy queries, userEvent, waitFor, and component testing.

UncategorizedID: pproenca/dot-skills/react-testing-library

Install this agent skill to your local

pnpm dlx add-skill https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/react-testing-library

Skill Files

Browse the full folder contents for react-testing-library.

Download Skill

Loading file tree…

skills/.experimental/react-testing-library/SKILL.md

Skill Metadata

Name
react-testing-library
Description
React Testing Library best practices for writing maintainable, user-centric tests. Use when writing, reviewing, or refactoring RTL tests. Triggers on test files, testing patterns, getBy/queryBy queries, userEvent, waitFor, and component testing.

React Testing Library Best Practices

Comprehensive testing guide for React components using Testing Library, designed for AI agents and LLMs. Contains 43 rules across 9 categories, prioritized by impact to guide test writing and code review.

When to Apply

Reference these guidelines when:

  • Writing new component tests with React Testing Library
  • Selecting queries (getByRole, getByLabelText, etc.)
  • Handling async operations in tests (findBy, waitFor)
  • Simulating user interactions (userEvent)
  • Reviewing tests for anti-patterns and implementation detail testing

Rule Categories by Priority

| Priority | Category | Impact | Prefix | |----------|----------|--------|--------| | 1 | Query Selection | CRITICAL | query- | | 2 | Async Handling | CRITICAL | async- | | 3 | Common Anti-Patterns | CRITICAL | anti- | | 4 | User Interaction | HIGH | user- | | 5 | Assertions | HIGH | assert- | | 6 | Component Setup | MEDIUM | setup- | | 7 | Test Structure | MEDIUM | struct- | | 8 | Debugging | LOW-MEDIUM | debug- | | 9 | Accessibility Testing | LOW | a11y- |

Quick Reference

1. Query Selection (CRITICAL)

2. Async Handling (CRITICAL)

3. Common Anti-Patterns (CRITICAL)

4. User Interaction (HIGH)

5. Assertions (HIGH)

6. Component Setup (MEDIUM)

7. Test Structure (MEDIUM)

8. Debugging (LOW-MEDIUM)

9. Accessibility Testing (LOW)

How to Use

Read individual reference files for detailed explanations and code examples:

Reference Files

| File | Description | |------|-------------| | references/_sections.md | Category definitions and ordering | | assets/templates/_template.md | Template for new rules | | metadata.json | Version and reference information |