Skip to content

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
Step-by-step guide: how to use EnzymeInstall, first run, examples, tips and FAQs

How to get it

  1. 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. 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. 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

ProjectStarsTypeLevelUpdatedBest for
enzyme (this)19.8kLibraryintermediate1.0 years agoDevelopers maintaining React codebases that already have component tests
react-testing-library19.7kLibrarybeginner2 months agoDevelopers writing automated tests for React applications
jest45.5kLibrarybeginner4 days agoJavaScript or TypeScript developers who want a testing setup that works with little configuration
mocha22.9kLibraryintermediate5 days agoJavaScript and Node.js developers who want automated tests for their code
pytest14.7kLibrarybeginner4 days agoPython developers who want to add automated tests to a project
javascript-testing-best-practices24.6kLearning resourcebeginner2.4 years agoDevelopers 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.