React
@testing-library/react
Simple and complete React DOM testing utilities that encourage good testing practices.
Testing
testing
react
ui
dom
jsdom
unit
integration
functional
end-to-end
e2e
Stars
20k
Weekly
40M
Open issues
82
Bundle
~15 kB
Installation
npm install @testing-library/reactCode example
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
function Counter() {
return <button type="button">Count</button>;
}
test("renders", async () => {
render(<Counter />);
await userEvent.click(screen.getByRole("button"));
expect(screen.getByRole("button")).toBeInTheDocument();
});Pros & cons
Pros
- Actively maintained by Kent C. Dodds
- 40M weekly downloads. Battle tested
- First-class TypeScript definitions
- MIT licensed
Considerations
- Adds roughly ~15 kB to your bundle
- Needs client-only rendering in SSR frameworks
- Not supported in React Native
- 82 open issues on GitHub