
react-testing-library
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.
- Installs
- 404
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/pproenca/dot-skills --skill react-testing-library- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads react-testing-library automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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)
query-prefer-role- Prefer getByRole over other queriesquery-avoid-testid- Avoid getByTestId as primary queryquery-use-screen- Use screen for queriesquery-label-text-forms- Use getByLabelText for form fieldsquery-role-name-option- Use name option with getByRolequery-get-vs-query- Use getBy for present, queryBy for absentquery-within-scope- Use within() to scope queries
2. Async Handling (CRITICAL)
async-findby-over-waitfor- Use findBy instead of waitFor + getByasync-await-findby- Always await findBy queriesasync-single-assertion-waitfor- Single assertion in waitForasync-no-side-effects-waitfor- Avoid side effects in waitForasync-waitfor-disappear- Use waitForElementToBeRemoved
3. Common Anti-Patterns (CRITICAL)
anti-unnecessary-act- Avoid unnecessary act() wrappinganti-manual-cleanup- Remove manual cleanup callsanti-implementation-details- Avoid testing implementation detailsanti-empty-waitfor- Avoid empty waitFor callbacksanti-container-queries- Avoid using container for queriesanti-redundant-roles- Avoid adding redundant ARIA roles
4. User Interaction (HIGH)
user-prefer-userevent- Use userEvent over fireEventuser-setup-before-render- Setup userEvent before renderuser-await-interactions- Always await userEvent interactionsuser-keyboard-for-special-keys- Use keyboard() for special keysuser-clear-before-type- Use clear() before retyping
5. Assertions (HIGH)
assert-jest-dom-matchers- Use jest-dom matchersassert-visible-over-in-document- Use toBeVisible() for visibilityassert-text-content- Use toHaveTextContent() for textassert-have-value- Use toHaveValue() for inputsassert-accessible-description- Use toHaveAccessibleDescription()
6. Component Setup (MEDIUM)
setup-wrapper-providers- Use wrapper option for providerssetup-custom-render- Create custom render with providerssetup-mock-modules- Mock modules at module levelsetup-fake-timers- Configure userEvent with fake timerssetup-render-hook- Use renderHook for testing hooks
7. Test Structure (MEDIUM)
struct-arrange-act-assert- Follow Arrange-Act-Assert patternstruct-one-behavior-per-test- Test one behavior per teststruct-descriptive-names- Use descriptive test namesstruct-avoid-beforeeach-render- Avoid render() in beforeEach
8. Debugging (LOW-MEDIUM)
debug-screen-debug- Use screen.debug() to inspect DOMdebug-logroles- Use logRoles to find available rolesdebug-testing-playground- Use Testing Playground for queries
9. Accessibility Testing (LOW)
a11y-role-queries-verify- Role queries verify accessibilitya11y-verify-focus- Test focus managementa11y-test-aria-states- Test ARIA states and properties
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
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 |
FAQ
What does the react-testing-library skill do?
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.
How do I install react-testing-library?
Run npx skills add https://github.com/pproenca/dot-skills --skill react-testing-library in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/react-testing-library/ (personal) or .claude/skills/react-testing-library/ (project).
Which AI agents can use react-testing-library?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is react-testing-library safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains react-testing-library?
It is published by pproenca in pproenca/dot-skills. It has 404 recorded installs.
More from pproenca/dot-skills
zod
pproenca/dot-skills
Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).
vitest
pproenca/dot-skills
Vitest testing framework patterns for test setup, async testing, mocking with vi., snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.
react-hook-form
pproenca/dot-skills
React Hook Form performance optimization for client-side form validation using useForm, useWatch, useController, useFieldArray, the subscribe() API, and the Watch / FormStateSubscribe / FieldArray render-prop components. Covers RHF 7.82 additions including resetDefaultValues() and the disabled field-array option. This skill should be used when building client-side controlled forms with React Hook Form library. This skill does NOT cover React 19 Server Actions, useActionState, or server-side form handling (use react-19 skill for those).
emilkowal-animations
pproenca/dot-skills
Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.
nuqs
pproenca/dot-skills
nuqs (type-safe URL query state) best practices for Next.js and other React frameworks. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, limitUrlUpdates, Standard Schema, NuqsAdapter, or Next.js routing with state.
clean-architecture
pproenca/dot-skills
Clean Architecture principles and best practices from Robert C. Martin's book. This skill should be used when designing software systems, reviewing code structure, or refactoring applications to achieve better separation of concerns. Triggers on tasks involving layers, boundaries, dependency direction, entities, use cases, or system architecture.
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work