🧪
Testing2M+/wkMIT

enzyme

Enzyme is a JavaScript testing utility for React developed by Airbnb that provides an intuitive API for rendering, traversing, and asserting on React component

Installation

npm
npm install -D enzyme
yarn
yarn add -D enzyme
pnpm
pnpm add -D enzyme

Import

ESM
import { shallow } from 'enzyme';

Quick Example

usage
import { shallow } from 'enzyme';
import MyComponent from './MyComponent';

const wrapper = shallow(<MyComponent title="Test" />);
expect(wrapper.find('h1').text()).toEqual('Test');
expect(wrapper.find('.active')).toHaveLength(1);

About enzyme

Enzyme is a JavaScript testing utility for React developed by Airbnb that provides an intuitive API for rendering, traversing, and asserting on React component output. Enzyme offers three rendering modes: shallow rendering that isolates a component from its children for unit testing, full DOM rendering via mount for testing component lifecycle and interaction with the DOM, and static rendering via render for generating static HTML markup. The library provides jQuery-like traversal methods including find(), children(), parents(), closest(), and filter() for locating elements in the rendered output, and simulation methods like simulate() for triggering events on components. Enzyme's API allows testing implementation details like component state, props, and instance methods, which made testing React components very straightforward but also coupled tests to implementation. Enzyme has been largely superseded by Testing Library, which encourages testing from the user's perspective rather than the component's internals. Enzyme does not support React 18+ without community adapters and is considered legacy by the React team, but it remains in active use across many existing codebases.

Quick Facts

Packageenzyme
CategoryTesting
Weekly Downloads2M+
LicenseMIT
Installnpm install -D enzyme

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.