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 install -D enzyme
yarn add -D enzyme
pnpm add -D enzyme
Import
import { shallow } from 'enzyme';Quick Example
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
| Package | enzyme |
| Category | Testing |
| Weekly Downloads | 2M+ |
| License | MIT |
| Install | npm install -D enzyme |
Related Packages
Testing Library is a family of packages that helps you test UI components in a way that resembles ho…
React is the most popular JavaScript library for building user interfaces, developed and maintained …
Jest is a delightful JavaScript testing framework with a focus on simplicity, created by Facebook. I…
Sinon.js provides standalone test spies, stubs, and mocks for JavaScript that work with any test fra…
Mocha is a feature-rich JavaScript test framework that runs on Node.js and in the browser, providing…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.