
React Testing Library
Lightweight utilities for testing React components by how users interact with them.
- Stars
- 19.7k
- Forks
- 1.2k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 2 months ago
- Type
- Library
What it is
React Testing Library is a small JavaScript package that helps you write automated tests for React components. It sits on top of react-dom and encourages tests that look like how a person uses the software, such as finding elements by their text or label, so tests keep working when internal code is refactored.
- Render a React component in a test and check what text or elements appear
- Simulate clicks and form input, then assert the result on screen
- Test a login form that calls an API by combining it with a mock service tool such as Mock Service Worker (the README shows this pattern)
- Add the jest-dom matchers for more readable assertions
Great for
- Developers writing automated tests for React applications
- Teams who want tests that survive refactors of component internals
- Projects on React 18 or newer (version 12 is noted for older React)
- Developers who prefer testing behavior over implementation details
Not ideal for
- Projects not using React, since it is specifically for React DOM components
- Teams on React versions older than 18 who cannot use the v12 release line (the README says v13+ requires React 18)
- People looking for an end-to-end browser testing tool; the README describes it as a component/DOM testing utility
How to get it
- 1
Install with a package manager
You'll need: Node.js (npm or yarn) · A React project
Install with npm
npm install --save-dev @testing-library/react @testing-library/domInstall with yarn
yarn add --dev @testing-library/react @testing-library/dom - 2
Run it
- Install the packages as devDependencies using npm or yarn
- Create a test file, for example __tests__/hidden-message.js
- Import render and screen from @testing-library/react and render your component
- Use queries like screen.getByText or screen.getByLabelText and fireEvent to interact, then assert with expect
- 3
Get the most out of it
- Add @testing-library/jest-dom for readable matchers such as toBeInTheDocument
- Prefer query methods that match how users find elements, as the README's guiding principle recommends
- Use query* methods when expecting absence and get* methods when expecting presence, as the examples show
- Combine with Mock Service Worker (msw) to test components that call APIs
Downloads
Strengths
- Encourages tests that focus on user-visible behavior rather than implementation details
- Very lightweight, built directly on react-dom and react-dom/test-utils
- Well documented, with a public docs site and a large community (about 19.7k stars)
Trade-offs
- Requires a separate @testing-library/dom install from version 16 onward, adding setup steps
- Older React versions need an older major release (v12 for React below 18)
- The README is truncated here, so details of advanced configuration are not covered in this entry
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| react-testing-library (this) | 19.7k | Library | beginner | 2 months ago | Developers writing automated tests for React applications |
| enzyme | 19.8k | Library | intermediate | 1.0 years ago | Developers maintaining React codebases that already have component tests |
| zustand | 58.9k | Library | beginner | 15 days ago | React developers who want simpler shared state than Redux |
| jest | 45.5k | Library | beginner | 4 days ago | JavaScript or TypeScript developers who want a testing setup that works with little configuration |
| react-hook-form | 44.9k | Library | intermediate | 5 days ago | React developers building forms with several fields |
| table | 28.5k | Library | intermediate | 16 days ago | Developers building custom data tables in React, Vue, Solid, Svelte or another supported framework |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.