Key takeaway
- Compare React Testing Library, Jest and Enzyme for component testing: current roles, React 19 guidance, snapshot limits and how to choose for your team.
How should enterprise teams test React components?
Test React components the way a user meets them: render the component, interact through roles, labels and visible text, and assert on what appears on screen. According to the React Testing Library documentation, "the more your tests resemble the way your software is used, the more confidence they can give you". Jest then runs those tests, and Enzyme is now a legacy option for existing suites rather than a starting point.
For CTOs and engineering leads the choice matters because brittle tests slow every release and block framework upgrades. This guide compares React Testing Library, Jest and Enzyme, shows the current role of each, and sets out an adoption sequence. It builds on our guides to test-driven development with React and Jest and unit testing techniques.
Which tool should a React team choose?
The three names in the old title are not three versions of the same thing. Jest is a test runner, React Testing Library is a way of rendering and querying components, and Enzyme is an older component-inspection library. Most teams combine a runner with Testing Library.
| Tool | What it does | When it fits | Current status (checked 13 Nov 2026) |
|---|---|---|---|
| React Testing Library | Renders components into the DOM and queries them as a user would | Default choice for component tests | Recommended by React's own upgrade guide for React 19 |
| Jest | Test runner, assertions, mocks, coverage and snapshots | Running any JavaScript tests, including those written with Testing Library | Documentation shows version 30.5; Jest does not support Vite, where Vitest offers a Jest-compatible API, according to its docs |
| Enzyme | Shallow and full rendering with access to state and props | Maintaining an existing suite you cannot yet migrate | Its GitHub README lists adapters for React 16.x and older only; confirm on the repository before using it with a newer React |
Sources: Testing Library, Jest, Enzyme and the React 19 upgrade guide.
What does React's own guidance say about testing?
The React 19 upgrade guide is the clearest signal. It states that shallow rendering "depends on React internals and can block you from future upgrades" and recommends migrating tests to @testing-library/react. It also deprecates react-test-renderer, saying it "promotes testing implementation details". The act helper now imports from react rather than react-dom/test-utils, and the other test-utils functions were removed.
The act reference describes it as a helper that applies pending React updates before assertions, and notes that React Testing Library wraps its helpers in act and sets IS_REACT_ACT_ENVIRONMENT for you.
How do you write a first test with React Testing Library?
Install the library with its peer dependency, as its documentation shows:
npm install --save-dev @testing-library/react @testing-library/dom
Take a small component with state:
function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>Count: {count}</button>;
}
The test renders it, clicks the button as a user would, and checks the visible result. It uses the companion user-event library, whose documentation recommends calling userEvent.setup() before rendering:
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
test('increments the count when clicked', async () => {
const user = userEvent.setup();
render(<Counter />);
await user.click(screen.getByRole('button', { name: /count: 0/i }));
expect(screen.getByRole('button', { name: /count: 1/i })).toBeTruthy();
});
Install @testing-library/user-event separately and follow its installation page. The test needs a DOM environment such as jsdom, which you configure in Jest; confirm the current setting on the Jest configuration page.
Which query should you use?
The Testing Library query guidance orders queries by how accessible they are: getByRole, getByLabelText, getByPlaceholderText, getByText and getByDisplayValue first, then getByAltText and getByTitle, and getByTestId last because users cannot see it. Use queryBy to assert that something is absent and findBy for elements that appear asynchronously.
What does Jest add, and where do snapshots fit?
Jest supplies the runner, expect assertions, mocking and coverage. Its getting started page installs it with npm install --save-dev jest and runs it through an npm test script. Babel and TypeScript setups are documented there; note that Babel-based TypeScript support only transpiles, so Jest does not type-check your tests.
Snapshot tests store a serialised render next to the test and fail when the output changes. The snapshot testing guide says snapshot files should be committed and reviewed in code review, and warns against regenerating snapshots without examining why they failed. Keep snapshots small and deterministic, and treat them as a regression signal, not proof of correct behaviour. For the wider discipline, see our guide to regression testing.
Why is Enzyme a legacy choice?
Enzyme offers shallow, which renders one component without its children, and mount, which renders the full tree. It also lets tests read state and props. Those features encourage tests that check how a component is built rather than what a user sees, so a harmless refactor can break them. The Testing Library documentation positions itself as a replacement and says Enzyme's utilities make this principle harder to follow.
The Enzyme README lists official adapters up to React 16.x and none for React 17 or later, so verify support on the repository before relying on it. If you must keep Enzyme for now, freeze new Enzyme tests and write all new ones with Testing Library.
What are the benefits and costs of component testing?
| Benefit | Cost or trade-off |
|---|---|
| Catches regressions before release, which supports shift-left testing | More code to write and maintain |
| Lets developers refactor with confidence when tests avoid implementation details | Poorly written tests become brittle and slow the team |
| Reduces repeated manual checking | Does not replace end-to-end, accessibility or performance checks |
Component tests also do not tell you whether the page is fast. For that, read optimising React application performance.
How should you adopt this in a team?
- Standardise on Jest or another runner plus React Testing Library and user-event for all new component tests.
- Write tests against roles, labels and visible text, and use test IDs only as a last resort.
- Freeze new Enzyme and
react-test-renderertests, then migrate them as components change. - Review snapshot changes in pull requests and keep them small.
- Run the suite in continuous integration on every pull request.
If you are new to the framework itself, start with our React learning path. Teams that build AI agents into their React front ends can test agent outputs and workflows too: according to its site, AgentQA tests agent outputs and workflows continuously, and ElixirClaw is an agentic OS platform to build, orchestrate and govern AI agents and automation workflows while keeping humans in control.
To map one quality decision your AI agents should make, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently asked questions
Is Enzyme still usable with current React?
Its GitHub README lists official adapters for React 16.x and older and none for React 17 or later. React's own upgrade guide recommends moving away from shallow rendering, so plan a migration.
Do I need Jest if I use React Testing Library?
Testing Library renders and queries components but does not run tests. You need a runner such as Jest, or Vitest on Vite projects, which its docs describe as offering a Jest-compatible API.
What is the difference between getBy, queryBy and findBy?
The getBy queries throw if nothing matches, queryBy returns null so you can assert absence, and findBy is asynchronous and retries until the element appears or the default timeout passes.
Should snapshots be committed to version control?
Yes. Jest's documentation says snapshot files should be committed with the tests and reviewed like any other change.
Why did React deprecate react-test-renderer?
The React 19 upgrade guide says it uses its own renderer environment that does not match what users run and promotes testing implementation details.
Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE