# Testing Library — card for AI agents

Testing utilities for React encouraging testing user behavior.

Category: Testing · npm package `@testing-library/react` · latest version 16.3.3 (checked 2026-11-01)
Install: `npm install @testing-library/react`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## React Testing Library
- Install as a devDependency together with `@testing-library/dom` (required from v16): `npm install --save-dev @testing-library/react @testing-library/dom`. For TypeScript, add `@types/react` and `@types/react-dom`.
- If the project uses React older than 18, install `@testing-library/react@12`. Versions 13+ require React v18.
- Find elements the way a user would, by label text or visible text. Use `data-testid` only as an escape hatch when text and labels do not make sense.
- Use `queryBy*` to assert absence, because it returns `null`. Use `getBy*` when the element must exist, because it throws if it is not found. For UI that appears later, await a `findBy*` query, as the README's login example does with `await screen.findByRole('alert')`.
- Work with DOM nodes, not component instances. Keep implementation details out of assertions.
- Mock API calls with Mock Service Worker instead of stubbing `window.fetch`, as the README recommends.
- Test single-use custom hooks through the component that uses them, not in isolation.

## Agent Skills for it
- react-modernization from wshobson/agents: `npx skills add wshobson/agents --skill react-modernization`
- react-native-dev from MiniMax-AI/skills: `npx skills add MiniMax-AI/skills --skill react-native-dev`
- react-expert from Jeffallan/claude-skills: `npx skills add Jeffallan/claude-skills --skill react-expert`
- react-vite-dashboard from google-labs-code/stitch-skills: `npx skills add google-labs-code/stitch-skills --skill react-vite-dashboard`
- react-composition-patterns from tech-leads-club/agent-skills: `npx skills add tech-leads-club/agent-skills --skill react-composition-patterns`
- react-hook-form from midudev/autoskills: `npx skills add midudev/autoskills --skill react-hook-form`

## What it is
- React Testing Library is a set of light helpers for testing React components. The README describes it as "Simple and complete React DOM testing utilities that encourage good testing practices." The site says it "builds on top of DOM Testing Library by adding APIs for working with React components." Most of the query logic lives in that underlying DOM library. The repository was created on 2018-03-19 and is MIT licensed.
- The README gives one primary guiding principle: "The more your tests resemble the way your software is used, the more confidence they can give you." Kent C. Dodds posted the same sentence on X in March 2018. In the README examples, a test passes a component to `render`, finds elements through `screen` queries such as `getByLabelText`, and clicks or types with `fireEvent`. The site says tests "will work with actual DOM nodes" instead of component instances.
- The site calls it "a replacement for Enzyme". It says Enzyme's extra utilities make testing implementation details easier, which makes the guidelines harder to enforce there. The README says the library should be useful for testing single components or full React applications. The site says it is not a test runner, and that it works with any framework, though the maintainers prefer Jest.

## Caveats
- You still need a test runner: The site says plainly that this is not a test runner or framework. Something else has to run the tests and provide `expect`. Jest is the maintainers' preference, but the site says any framework works.
- A second package to install since v16: From RTL version 16, `@testing-library/dom` is a peer dependency. You install it yourself next to `@testing-library/react`.
- React 18 needed from v13: The README says versions 13 and up require React v18. Projects on older React should install version 12.
- Types come separately: For TypeScript, the site says to also install `@types/react` and `@types/react-dom` to get full type coverage.
- act() warnings on React DOM 16.8: The README describes a "known compatibility issue" with React DOM 16.8 that prints a "not wrapped in act(...)" warning. If you cannot upgrade to 16.9, it offers a `console.error` filter to silence it.

## Numbers (AgentGid data)
- Gid Score: 83.3 (#53 of all tools, 5 of 122 in its category)
- Used in 640 public projects set up for AI coding agents (10.2%)
- Downloads last week: 101,225,524 (as of 2026-11-24), +40.4% over 4 weeks
- GitHub stars: 19,686 (as of 2026-11-24)
- Last push: 2026-08-27

## Often used with
Vitest 74.1%, jsdom 64.8%, React 90.0%, Vite 65.9%, Tailwind CSS 74.5%, Lucide React 57.8%

## Checked alternatives (same job)
- Vitest: https://agentgid.com/tools/vitest/agent.md
- Jest: https://agentgid.com/tools/jest/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/testing-library/
- Homepage: https://github.com/testing-library/react-testing-library#readme
- Repository: https://github.com/testing-library/react-testing-library
- Source: https://github.com/testing-library/react-testing-library#readme
- Source: https://github.com/testing-library/react-testing-library
- Source: https://github.com/testing-library/react-testing-library/releases
- Source: https://testing-library.com/react
- Source: https://twitter.com/kentcdodds/status/977018512689455106

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
