Overview

Enzyme is a JavaScript testing utility designed to simplify the testing of React components. Developed by Airbnb, it provides a set of utilities for rendering React components into various environments and then querying, asserting, and manipulating their output. This makes it particularly useful for unit and integration testing where developers need to ensure components behave as expected without necessarily rendering them in a full browser environment.

Enzyme offers three primary rendering methods: shallow rendering, full DOM rendering, and static markup rendering. Shallow rendering is often favored for unit tests because it renders only the component itself, without its children, isolating the component under test from its dependencies and ensuring that tests for component A are not inadvertently affected by changes in component B. Full DOM rendering, on the other hand, renders the component into a real DOM attached to the global document, simulating a browser environment more closely and allowing for tests that interact with the component's lifecycle methods and the browser's DOM API. Static markup rendering is used to render React components to static HTML strings, which can be useful for snapshot testing or server-side rendering verification.

Developers use Enzyme to inspect the internal state of components, simulate user interactions like clicks and input changes, and assert on the structure and content of the rendered output. Its API provides methods for finding elements by props, state, or component name, and then interacting with them. While Enzyme remains a functional tool for React component testing, its development has seen a significant slowdown since its peak. For new projects, the React Testing Library is frequently recommended as an alternative due to its focus on testing user-facing behavior rather than implementation details, aligning with common testing best practices described by organizations like Google's web.dev in their guide to testing web components.

Enzyme is best suited for developers who need fine-grained control over component rendering and access to internal component states and methods during testing. It integrates well with test runners like Jest, providing a comprehensive solution for testing React applications. Its open-source nature means it is entirely free to use and contribute to, making it accessible for individual developers and large teams alike.

Key features

  • Shallow Rendering: Renders only the top-level component, without rendering its children, to isolate the component being tested. This is beneficial for unit tests, ensuring that tests for one component are not affected by changes in its child components.
  • Full DOM Rendering: Renders components into a real DOM environment, allowing for tests that require full lifecycle methods, DOM interactions, and context API usage. This is more akin to how a component would behave in a browser, making it suitable for integration tests.
  • Static Markup Rendering: Renders components to static HTML strings, which can be useful for verifying server-side rendering output or for snapshot testing.
  • Component Traversal and Selection: Provides an API for finding elements within the rendered component tree based on selectors like prop values, state, component names, or CSS classes, similar to jQuery.
  • Interaction Simulation: Enables the simulation of user interactions such as clicks, form submissions, and input changes, allowing developers to test how components respond to user events.
  • State and Prop Inspection: Offers methods to inspect and assert on the internal state and props of a React component, providing granular control over testing component logic.
  • Lifecycle Method Access: With full DOM rendering, Enzyme allows access to and interaction with React component lifecycle methods, facilitating testing of side effects and initializations.

Pricing

Enzyme is an open-source project and is entirely free to use. There are no paid tiers, subscriptions, or commercial licenses associated with its use or distribution.

Tier Cost (as of 2026-05-08) Features
Open Source Free Full access to all Enzyme features, community support.

Common integrations

  • Jest: Enzyme is commonly used in conjunction with Jest, a JavaScript testing framework, for running tests and providing assertion capabilities. Jest's snapshot testing feature often complements Enzyme's rendering utilities. Learn more about Jest on its official website.
  • Webpack/Babel: When testing React components, Webpack and Babel are often used for bundling and transpiling JavaScript and JSX code before tests are run. Enzyme integrates seamlessly into such build pipelines.
  • Chai: Although Jest provides its own assertion library, some developers prefer to use Chai with Enzyme for its flexible and expressive assertion syntax.
  • Sinon.js: For mocking and stubbing functions or components during tests, Sinon.js is a common choice that works well alongside Enzyme.

Alternatives

  • React Testing Library: A set of utilities for testing React components that focuses on testing user-facing behavior rather than internal implementation details.
  • Jest: A powerful JavaScript testing framework that includes a test runner, assertion library, and mocking capabilities, often used as the test runner with Enzyme or React Testing Library.
  • Cypress: An end-to-end testing framework for web applications that runs directly in the browser, offering a different approach to UI testing.

Getting started

To begin using Enzyme, you'll typically install it alongside a test runner like Jest and an adapter for your specific React version. Here's a basic example for setting up Enzyme with React 18:

# Install Enzyme, its React 18 adapter, and Jest
npm install --save-dev enzyme @wojtekmaj/enzyme-adapter-react-18 jest react react-dom

Next, configure Enzyme to use the adapter. This often happens in a setup file that Jest runs before your tests. Create a file like src/setupTests.js:

import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-18';

Enzyme.configure({ adapter: new Adapter() });

Ensure Jest is configured to load this setup file. You can add a setupFilesAfterEnv entry in your jest.config.js or package.json:

// In package.json
{
  "jest": {
    "setupFilesAfterEnv": [
      "./src/setupTests.js"
    ]
  }
}

Now you can write your first test using Enzyme. Consider a simple React component:

// src/MyComponent.js
import React from 'react';

function MyComponent({ name }) {
  return <div>Hello, {name}!</div>;
}

export default MyComponent;

And its corresponding test file:

// src/MyComponent.test.js
import React from 'react';
import { shallow } from 'enzyme';
import MyComponent from './MyComponent';

describe('MyComponent', () => {
  it('renders a greeting with the provided name', () => {
    const wrapper = shallow(<MyComponent name="World" />);
    expect(wrapper.text()).toEqual('Hello, World!');
  });

  it('contains a div element', () => {
    const wrapper = shallow(<MyComponent name="Test" />);
    expect(wrapper.find('div')).toHaveLength(1);
  });
});

Run your tests using jest from your terminal. This example demonstrates shallow rendering to test the component's output and structure in isolation. For more advanced use cases, including full DOM rendering and simulating interactions, refer to the Enzyme API documentation.