
Enzyme
A JavaScript testing utility that lets you inspect and simulate React component output in tests.
- Stars
- 19.8k
- Forks
- 2k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 1.0 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
Enzyme is a JavaScript testing utility for React. It lets developers check what a React component renders, find elements inside it, and simulate actions like clicks, with an API modeled on jQuery's traversal style. It is used alongside a test runner and assertion library such as Mocha, Chai, or Jest.
- Render a component with shallow() and assert how many child components it contains
- Mount a component with mount() and simulate a click on a button, then check a spy was called
- Use render() to generate static markup and check the text it contains
- Change props on a mounted component with setProps() and verify the output updates
Great for
- Developers maintaining React codebases that already have component tests
- Teams testing React 16 or older versions with a matching official adapter
- Developers who want shallow rendering to test one component in isolation
- Projects that use Mocha, Chai, Jest, or another test runner of their choice
Not ideal for
- Projects on React versions not covered by an adapter in the README, since compatibility is limited to the listed adapter versions
- People writing new React tests who want a current, actively documented approach; the README points to migration from Enzyme 2.x and does not describe a newer React testing path
- Hooks-heavy code using shallow rendering, because the README notes useEffect and useLayoutEffect are not called and useCallback does not memoize in shallow mode
How to get it
- 1
Install with a package manager
You'll need: Node.js and npm · React and react-dom matching your adapter version
Install enzyme and the React 16 adapter as dev dependencies
npm i --save-dev enzyme enzyme-adapter-react-16 - 2
Run it
- Install enzyme and the adapter that matches your React version
- Configure enzyme once in your test setup using Enzyme.configure({ adapter: new Adapter() })
- Write a test that calls shallow(), mount(), or render() on a component
- Use find() and assertions from your chosen test runner to check the output
- 3
Get the most out of it
- Use shallow() to test one component without rendering its children
- Use mount() for full DOM behavior when you need real event handling and lifecycle calls
- Add chai-enzyme, jest-enzyme, or another matcher library listed in the README for custom assertions
- Follow the framework-specific guides in the docs for Mocha, Jest, Webpack, or JSDOM setup
Downloads
Strengths
- Simple, readable API inspired by jQuery for finding and traversing rendered output
- Works with any test runner or assertion library, according to the README
- Supports shallow, full DOM, and static rendering modes in one library
Trade-offs
- Requires a separate adapter package matched to your React version, adding setup steps
- Shallow rendering has known gaps with React hooks as described in the README
- The README has a truncated section and gives limited detail on current maintenance status, so the project's future support is unclear from this text
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| enzyme (this) | 19.8k | Library | intermediate | 1.0 years ago | Developers maintaining React codebases that already have component tests |
| react-testing-library | 19.7k | Library | beginner | 2 months ago | Developers writing automated tests for React applications |
| jest | 45.5k | Library | beginner | 4 days ago | JavaScript or TypeScript developers who want a testing setup that works with little configuration |
| mocha | 22.9k | Library | intermediate | 5 days ago | JavaScript and Node.js developers who want automated tests for their code |
| pytest | 14.7k | Library | beginner | 4 days ago | Python developers who want to add automated tests to a project |
| javascript-testing-best-practices | 24.6k | Learning resource | beginner | 2.4 years ago | Developers who already write some JavaScript tests and want to improve their structure |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.