3. Used by agents' projects
Dependency in 640 public GitHub projects set up for AI coding agents that we scanned (10.2%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
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
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
Often used with
Testing Library in practice
Strengths
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.
The README states this goal directly. A refactor changes the implementation but not the behavior, and it should leave the tests passing.
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.
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
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.
From RTL version 16, <code>@testing-library/dom</code> is a peer dependency. You install it yourself next to <code>@testing-library/react</code>.
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
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
Alternatives
Testing Library This page
Next-generation testing framework powered by Vite with native ESM.
Delightful JavaScript testing framework with minimal configuration.
Get started
Install it.
npm install @testing-library/reactRules for your agent
## 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.