Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

@testing-library/react 14.2.1

Simple and complete React DOM testing utilities that encourage good testing practices.
Package summary
Share
0
issues
0
licenses
Package created
30 May 2019
Version published
1 Feb 2024
Maintainers
15
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does @testing-library/react do?

The @testing-library/react is a comprehensive set of testing utilities for React that encourages good testing practices. It provides light utility functions on top of react-dom and react-dom/test-utils, promoting better testing practices. This library is focused on making your tests resemble the way your software is used, supporting both React Hooks and Classes.

How do you use @testing-library/react?

To use @testing-library/react, you first need to install it as a devDependency in your project using npm or yarn. Installation can be done with the following shell commands:

  • With npm:
npm install --save-dev @testing-library/react
  • With yarn:
yarn add --dev @testing-library/react

In a simple use case, here is how to use it:

import { render, screen } from '@testing-library/react';
import MyComponent from './MyComponent';

test('renders learn react link', () => {
  render(<MyComponent />);
  const linkElement = screen.getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

This testing pattern uses tools from the library to render a React component, query the rendered output, and make assertions based on the queried output.

For complex usage and more examples, refer to the documentation or the project's GitHub repository.

Where are the @testing-library/react docs?

The official @testing-library/react documentation can be found here. The docs give you an in-depth understanding of how to use the library, different utilities it provides, and examples of how to use them. You can also find various useful examples of testing different libraries in react-testing-library-examples codesandbox.