testing-library /react-testing-library

🐐 Simple and complete React DOM testing utilities that encourage good testing practices.

★ 19,682⑂ 1,171👁 137⑃ 549● 840▤ 208
JavaScriptMITCreated 2018-03-19testing-library.com/react
Download: v16.3.3v16.3.3 ↓16.3.32026-08-27
+1
Daily
19,682
stars
1,171
forks
137
watchers
549
prs
840
issues
208
releases

README

React Testing Library


  


Simple and complete React DOM testing utilities that encourage good testing
practices.



Read The Docs |
Edit the docs







[![Build Status][build-badge]][build]
[![Code Coverage][coverage-badge]][coverage]
[![version][version-badge]][package]
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]
[![All Contributors][all-contributors-badge]](contributors)
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]
[![Discord][discord-badge]][discord]

[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]



  
    
  


 Table of Contents




- The problem
- The solution
- Installation
  - Suppressing unnecessary warnings on React DOM 16.8
- Examples
  - Basic Example
  - Complex Example
  - More Examples
- Hooks
- Guiding Principles
- Docs
- Issues
  - 🐛 Bugs
  - 💡 Feature Requests
  - ❓ Questions
- Contributors
- LICENSE



 The problem

You want to write maintainable tests for your React components. As a part of
this goal, you want your tests to avoid including implementation details of your
components and rather focus on making your tests give you the confidence for
which they are intended. As part of this, you want your testbase to be
maintainable in the long run so refactors of your components (changes to
implementation but not functionality) don't break your tests and slow you and
your team down.

 The solution

The React Testing Library is a very lightweight solution for testing React
components. It provides light utility functions on top of react-dom and
react-dom/test-utils, in a way that encourages better testing practices. Its
primary guiding principle is:

 [The more your tests resemble the way your software is used, the more
 confidence they can give you.][guiding-principle]

 Installation

This module is distributed via [npm][npm] which is bundled with [node][node] and
should be installed as one of your project's devDependencies.  
Starting from RTL version 16, you'll also need to install
@testing-library/dom:


npm install --save-dev @testing-library/react @testing-library/dom


or

for installation via [yarn][yarn]


yarn add --dev @testing-library/react @testing-library/dom


This library has peerDependencies listings for react, react-dom and
starting from RTL version 16 also @testing-library/dom.

_React Testing Library versions 13+ require React v18. If your project uses an
older version of React, be sure to install version 12:_


npm install --save-dev @testing-library/react@12


yarn add --dev @testing-library/react@12


You may also be interested in installing @testing-library/jest-dom so you can
use the custom jest matchers.

 Docs

 Suppressing unnecessary warnings on React DOM 16.8

There is a known compatibility issue with React DOM 16.8 where you will see the
following warning:


Warning: An update to ComponentName inside a test was not wrapped in act(...).


If

Top issues

Latest release

v16.3.3 v16.3.3 2026-08-27
16.3.3 (2026-08-27)


 Bug Fixes

 Avoid act() re-entrant when dispatching events (1468) (20ce75f)

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON