Skip to main content
XenonStack

Cloud Native Applications

XenonStack Blog Unit Testing in React: Jest, Testing Library or Enzyme

and | Published | Updated

Unit Testing in React: Jest, Testing Library or Enzyme
10:20

Key takeaway

  • Unit testing in React: compare Jest, React Testing Library and Enzyme, see what to test, and follow a migration sequence for enterprise front-end teams.

For a new React project, test with Jest as the runner and React Testing Library to render components and query them the way a user sees them. Enzyme is still found in older codebases, but its README lists adapters only up to React 16, and the React team now recommends React Testing Library for tests (as stated in the React 19 upgrade guide). The sensible plan for most teams is to keep Enzyme tests running while they write every new test in Testing Library.

This guide is for CTOs, engineering heads and architects who need to decide a test standard for React front ends. It explains the arrange, act and assert pattern, compares the three tools in a decision table, shows a minimal setup, and sets out a migration sequence. For the wider practice, read our guides to test-driven development and test-driven development with React and Jest.

What is unit testing in React and why does it matter?

A unit test checks one component or function in isolation and fails when its behaviour changes. In React, the unit is usually a component: given these props and this user action, does it show the right output? Fast unit tests give developers quick feedback and a safety net when they add features or refactor, which is what keeps release cadence steady as a code base grows.

Every test follows the same three steps, and naming them keeps tests readable for the whole team.

StepWhat it meansReact example
ArrangePut the component in a known starting stateRender a login form with the props and mock services it needs
ActDo what a user would doType an email address and click the login button
AssertCheck the visible outcomeAn error message appears, or the submit handler is called once

If the assertion fails, either the component has a defect or the test describes behaviour that no longer exists. Both are worth knowing early. For acceptance-level checks that sit above unit tests, see our guide to user acceptance testing.

Which tool should you use: Jest, React Testing Library or Enzyme?

The three names are often compared as if they were rivals, but they do different jobs. Jest runs tests, provides assertions, mocks and snapshots. React Testing Library and Enzyme help tests render components and interact with them, so each needs a test runner such as Jest. The decision is therefore between the two component-testing libraries, with Jest as the usual runner.

Two-column diagram mapping testing needs (run tests, render like a user, inspect internals, record output changes) to Jest, React Testing Library, Enzyme and Jest snapshots.
ToolWhat it doesWhen it fitsCurrent status
JestTest runner, assertion library, mocking and snapshot testingAlmost every React project; the default runner in most setupsActively released; the docs at jestjs.io show version 30.5 (read 11 Nov 2026)
React Testing LibraryRenders components and queries them as a user would; not a test runnerAll new tests; its guiding principle is that tests should resemble the way the software is usedRecommended by the React team in the React 19 upgrade guide
EnzymeShallow and full rendering, with access to component state, props and childrenMaintaining existing suites during a migrationREADME lists adapters for React 16.x down to 0.13.x only, with no mention of React 17 or 18

Two further points affect the choice. First, Create React App was deprecated for new apps on 14 February 2025, so new projects usually start from a framework such as Next.js or React Router, or a build tool such as Vite, and the test runner is configured there. Second, the React 19 guide deprecates react-test-renderer and says shallow rendering depends on React internals and can block future upgrades, which is the same weakness that affects Enzyme-style tests.

How do the three approaches differ in practice?

What Jest provides

Jest is a JavaScript testing framework that works with Babel, TypeScript, Node, React and Vue projects. Install it with npm install --save-dev jest, add "test": "jest" to the scripts in package.json, and run npm test. Snapshot tests record the rendered output of a component and flag any later change, which is quick to write but only tells you that something changed, not whether it matters.

What React Testing Library provides

React Testing Library builds on DOM Testing Library with APIs for React components. It is not a test runner, works with any test framework, and its authors recommend Jest. Install @testing-library/react together with its peer dependency @testing-library/dom. Because it renders to the DOM and queries by what the user sees, there is no shallow rendering mode.

import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import Login from "./Login";

test("shows an error when the fields are empty", async () => {
  render(<Login />);
  await userEvent.click(screen.getByRole("button", { name: /login/i }));
  expect(screen.getByText(/required/i)).toBeInTheDocument();
});

The example assumes the @testing-library/user-event and @testing-library/jest-dom helper packages are installed. Treat it as a pattern to adapt, not a drop-in file.

What Enzyme provides

Enzyme is a JavaScript testing utility for React that makes it easier to assert on, manipulate and traverse components, including through shallow rendering. It needs an adapter that matches your React version, and the adapter list in its README stops at React 16. That is the main risk of keeping it on a current React release.

What should you test, and what should you leave alone?

Test behaviour that users and downstream teams depend on: what renders for given props, what happens on click, what an error state looks like, and which handler is called. Do not test implementation details such as variable names or the name of an internal function. If a handler is renamed from handleClick to onSubmit and the button still works, the test should still pass. Tests tied to internal names fail on harmless refactors, and teams soon stop trusting them.

Do not write tests for third-party libraries either. Check that the library is well tested and maintained before you adopt it, then test your own integration with it. A login component is a good sample: render the form, submit it empty, enter an invalid email, then enter valid details and confirm the login call is made. Wrap routed components in a memory router and pass mock store data so each test controls its own environment. Test data for such cases should be planned deliberately; our overview of test data management covers the options.

What governance, security and cost issues should leadership weigh?

AreaQuestion to askPractical rule
Maintenance riskDoes the tool support the React version we run?Do not add new Enzyme tests; check adapter support before every React upgrade
Upgrade costHow many tests depend on internal state or shallow rendering?Count them; they are the ones that will break on upgrade
Pipeline controlDo failing tests block a merge?Run the suite in CI and make a failing test a blocking check
Test dataDo tests use real customer data?Use mocks and synthetic fixtures; never copy production data into test files
Build effortWho owns the test setup?Keep one shared config in the project template so every team starts the same way

Teams that now ship AI agents inside products need the same discipline for agent behaviour. AgentQA describes itself as quality assurance for agent workflows, outputs and regression risk, which is the agent-side counterpart to a component test suite. For governed delivery of agents across teams, see ElixirClaw, an enterprise agentic OS for multi-agent orchestration, workflow automation and analytics.

How do you adopt this in sequence?

StepActionDone when
1Set Jest as the single runner and add the test script to the project templateEvery repository runs npm test the same way
2Add React Testing Library for all new component testsNew pull requests contain no new Enzyme tests
3List existing Enzyme and snapshot-only tests by riskYou know which suites break on the next React upgrade
4Rewrite the high-risk suites as behaviour testsTests describe what users see, not internal state
5Make the suite a blocking pipeline stageA failing test stops the merge

What are the trade-offs, and when should you not follow this advice?

Testing Library tests need a DOM environment and run slower than pure function tests, and querying by role means components must be accessible, which is a benefit but takes effort in older code. Snapshot tests are cheap to write but easy to approve without reading. Rewriting a stable Enzyme suite that still passes and sits on an old React version may not repay the cost; in that case freeze it and rewrite it when the component next changes. Unit tests also do not replace end-to-end or acceptance testing, so pair them with both.

To map one decision your engineering and 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 supported for React?

The Enzyme README lists adapters for React 16.x, 15.x, 0.14.x and 0.13.x and does not mention React 17 or 18, so check adapter support before relying on it with a current React version.

Do I need Jest to use React Testing Library?

React Testing Library is not a test runner. It works with any test framework, and its authors recommend Jest.

What does the React team recommend for testing?

The React 19 upgrade guide deprecates react-test-renderer and recommends migrating tests to @testing-library/react.

Should I test function and variable names?

No. Test behaviour users see. Tests tied to internal names fail on harmless refactors.

How do I install and run Jest?

Run npm install --save-dev jest, add a test script with the value jest to package.json, then run npm test.

Is Create React App still the way to start a React project?

The React team deprecated it for new apps on 14 February 2025 and recommends a framework or a build tool such as Vite.

Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in solving your challenges with the XenonStack team?
Get Started

Tell us about you and your priorities so we can prepare the right conversation. It takes about 2 minutes.

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Continue