Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

Testing Library

Testing utilities for React encouraging testing user behavior.

TestingNPM

GitHubWebsite

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What Testing Library does

React Testing Library gives you no supported way into component instances: tests work on real DOM nodes and find elements by label, text or role, as a user would.

Testing Library popularity

83 / 100
Gid Score, #53 overall
101M
downloads a week, npm
19.7K
GitHub stars
640
agent projects use it
Testing Library: downloads per weeknpm, @testing-library/react 101,225,524
Testing Library: GitHub starstesting-library/react-testing-library 19,686

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How Testing Library is used

  • Testing Library is a dependency in 640 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (13.1% of the 4,867 JavaScript/TypeScript ones), #3 of 122 in testing.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,483; those are left out of every share on this page.
  • The most used alternative in our scan is Vitest (1,312 projects).
  • Projects that use it most often also use Vitest (74.1%), jsdom (64.8%), React (90.0%).
  • It is more common in projects set up for Devin Desktop (16.8%) than for GitHub Copilot (9.0%).

By coding agent

391 projects, 11.9%
331 projects, 13.6%
273 projects, 9.0%
71 projects, 15.1%
68 projects, 14.3%
47 projects, 16.8%
40 projects, 11.7%
23 projects, 16.4%

Often used with

In 74.1% of its projects
In 64.8% of its projects
In 90.0% of its projects
In 65.9% of its projects
In 74.5% of its projects
In 57.8% of its projects
In 78.0% of its projects
In 94.5% of its projects

Testing Library in practice

Strengths

Queries match how users find things

The site says the utilities support querying the DOM "in the same way the user would". Form fields are found by their label text. Links and buttons are found by their text.

Refactors are not supposed to break tests

The README states this goal directly. A refactor changes the implementation but not the behavior, and it should leave the tests passing.

Hooks or classes, same test

A comment in the README's basic example says the library works with both component styles. It also says your tests stay the same however the component is written.

A sanctioned escape hatch

Some elements have no useful text or label. For those, the site points to a recommended <code>data-testid</code> query, so you do not have to invent your own selectors.

Watch out for

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 <code>expect</code>. Jest is the maintainers' preference, but the site says any framework works.

A second package to install since v16

From RTL version 16, <code>@testing-library/dom</code> is a peer dependency. You install it yourself next to <code>@testing-library/react</code>.

React 18 needed from v13

The README says versions 13 and up require React v18. Projects on older React should install version 12.

Toggle a checkbox, check the message appears

// __tests__/hidden-message.js
// these imports are something you'd normally configure Jest to import for you
// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup
import '@testing-library/jest-dom'
// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required

import * as React from 'react'
import {render, fireEvent, screen} from '@testing-library/react'
import HiddenMessage from '../hidden-message'

test('shows the children when the checkbox is checked', () => {
  const testMessage = 'Test Message'
  render(<HiddenMessage>{testMessage}</HiddenMessage>)

  // query* functions will return the element or null if it cannot be found
  // get* functions will return the element or throw an error if it cannot be found
  expect(screen.queryByText(testMessage)).toBeNull()

  // the queries can accept a regex to make your selectors more resilient to content tweaks and changes.
  fireEvent.click(screen.getByLabelText(/show/i))

  // .toBeInTheDocument() is an assertion that comes from jest-dom
  // otherwise you could use .toBeDefined()
  expect(screen.getByText(testMessage)).toBeInTheDocument()
})

More about Testing Library

Agent Skills for it
  • react-modernization: Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing R
  • react-native-dev: React Native and Expo development guide covering components, styling, animations, navigation, state management, forms, networking, performan
  • react-expert: Use when building React 18+ applications in .jsx or .tsx files, Next.js App Router projects, or create-react-app setups. Creates components,
  • react-vite-dashboard: Convert Stitch designs into production React + Vite dashboards with TanStack Query, accessible tokens from DESIGN.md, and Web3-ready pattern
  • react-composition-patterns: React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component librarie
  • react-hook-form: React Hook Form performance optimization for client-side form validation using useForm, useWatch, useController, useFieldArray, the subscrib

See all

Packages around it
  • @testing-library/jest-dom: Custom DOM matchers for expect
  • @testing-library/user-event: Simulated user interactions
  • @testing-library/dom: Core queries, required peer
  • @testing-library/react-native: React Native variant
  • @testing-library/jest-native: Matchers for React Native
  • @testing-library/svelte: Svelte variant
More in Testing

Alternatives

Testing Library This page

MITGid 83101M/wk

Vitest

Next-generation testing framework powered by Vite with native ESM.

MITGid 86194M/wk

Jest

Delightful JavaScript testing framework with minimal configuration.

MITGid 8663.2M/wk

Compare Testing Library with another tool

Get started

Install it.

npm install @testing-library/react

Rules for your agent

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.