Github url


by enzymejs

enzymejs /enzyme

JavaScript Testing utilities for React

18.9K Stars 2.0K Forks Last release: Not found MIT License 1.9K Commits 270 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Join the chat at

npm Version License Build Status Coverage Status

Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output. You can also manipulate, traverse, and in some ways simulate runtime given the output.

Enzyme's API is meant to be intuitive and flexible by mimicking jQuery's API for DOM manipulation and traversal.

Upgrading from Enzyme 2.x or React < 16

Are you here to check whether or not Enzyme is compatible with React 16? Are you currently using Enzyme 2.x? Great! Check out our migration guide for help moving on to Enzyme v3 where React 16 is supported.


To get started with enzyme, you can simply install it via npm. You will need to install enzyme along with an Adapter corresponding to the version of react (or other UI Component library) you are using. For instance, if you are using enzyme with React 16, you can run:

npm i --save-dev enzyme enzyme-adapter-react-16

Each adapter may have additional peer dependencies which you will need to install as well. For instance,


has peer dependencies on





At the moment, Enzyme has adapters that provide compatibility with

React 16.x


React 15.x


React 0.14.x


React 0.13.x


The following adapters are officially provided by enzyme, and have the following compatibility with React:

| Enzyme Adapter Package | React semver compatibility | | --- | --- | |




| |




| |




| |


| ~16.0.0-0 || ~16.1 | |




| |



15.0.0-0 - 15.4.x

| |




| |





Finally, you need to configure enzyme to use the adapter you want it to use. To do this, you can use the top level



import Enzyme from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; Enzyme.configure({ adapter: new Adapter() });

3rd Party Adapters

It is possible for the community to create additional (non-official) adapters that will make enzyme work with other libraries. If you have made one and it's not included in the list below, feel free to make a PR to this README and add a link to it! The known 3rd party adapters are:

| Adapter Package | For Library | Status | | --- | --- | --- | | [


]( | [


]( | (stable) | |[




](|(work in progress)|

Running Enzyme Tests

Enzyme is unopinionated regarding which test runner or assertion library you use, and should be compatible with all major test runners and assertion libraries out there. The documentation and examples for enzyme use mocha and chai, but you should be able to extrapolate to your framework of choice.

If you are interested in using enzyme with custom assertions and convenience functions for testing your React components, you can consider using:

Using Enzyme with Mocha

Using Enzyme with Karma

Using Enzyme with Browserify

Using Enzyme with SystemJS

Using Enzyme with Webpack

Using Enzyme with JSDOM

Using Enzyme with React Native

Using Enzyme with Jest

Using Enzyme with Lab

Using Enzyme with Tape and AVA

Basic Usage

Shallow Rendering

import React from 'react'; import { expect } from 'chai'; import { shallow } from 'enzyme'; import sinon from 'sinon'; import MyComponent from './MyComponent'; import Foo from './Foo'; describe('<mycomponent></mycomponent>', () =\> { it('renders three <foo></foo> components', () =\> { const wrapper = shallow(<mycomponent></mycomponent>); expect(wrapper.find(Foo)).to.have.lengthOf(3); }); it('renders an `.icon-star`', () =\> { const wrapper = shallow(<mycomponent></mycomponent>); expect(wrapper.find('.icon-star')).to.have.lengthOf(1); }); it('renders children when passed in', () =\> { const wrapper = shallow(( <mycomponent>
        <div classname="unique"></div>
      </mycomponent> )); expect(wrapper.contains(

)).to.equal(true); }); it('simulates click events', () =\> { const onButtonClick = sinon.spy(); const wrapper = shallow(<foo onbuttonclick="{onButtonClick}"></foo>); wrapper.find('button').simulate('click'); expect(onButtonClick)'callCount', 1); }); });

Read the full API Documentation

Full DOM Rendering

import React from 'react'; import sinon from 'sinon'; import { expect } from 'chai'; import { mount } from 'enzyme'; import Foo from './Foo'; describe('<foo></foo>', () =\> { it('allows us to set props', () =\> { const wrapper = mount(<foo bar="baz"></foo>); expect(wrapper.props().bar).to.equal('baz'); wrapper.setProps({ bar: 'foo' }); expect(wrapper.props().bar).to.equal('foo'); }); it('simulates click events', () =\> { const onButtonClick = sinon.spy(); const wrapper = mount(( <foo onbuttonclick="{onButtonClick}"></foo> )); wrapper.find('button').simulate('click'); expect(onButtonClick)'callCount', 1); }); it('calls componentDidMount', () =\> { sinon.spy(Foo.prototype, 'componentDidMount'); const wrapper = mount(<foo></foo>); expect(Foo.prototype.componentDidMount)'callCount', 1); Foo.prototype.componentDidMount.restore(); }); });

Read the full API Documentation

Static Rendered Markup

import React from 'react'; import { expect } from 'chai'; import { render } from 'enzyme'; import Foo from './Foo'; describe('<foo></foo>', () =\> { it('renders three `.foo-bar`s', () =\> { const wrapper = render(<foo></foo>); expect(wrapper.find('.foo-bar')).to.have.lengthOf(3); }); it('renders the title', () =\> { const wrapper = render(<foo title="unique"></foo>); expect(wrapper.text()).to.contain('unique'); }); });

Read the full API Documentation

React Hooks support

Enzyme supports react hooks with some limitations in [


]( due to upstream issues in React's shallow renderer:

  • useEffect()



    don't get called in the React shallow renderer. Related issue


doesn't memoize callback in React shallow renderer. Related issue



]( wrap

If you're using React 16.8+ and


, Enzyme will wrap apis including [


](, [


](, [


](, [


]( with [


]( so you don't need to manually wrap it.

A common pattern to trigger handlers with


and assert is:

const wrapper = mount(<somecomponent></somecomponent>); act(() =\> wrapper.prop('handler')()); wrapper.update(); expect(/\* ... \*/);

We cannot wrap the result of




) with


in Enzyme internally since it will break the equality of the returned value. However, you could use


to simplify the code:

const wrapper = mount(<somecomponent></somecomponent>); wrapper.invoke('handler')(); expect(/\* ... \*/);


Enzyme Future


See the Contributors Guide

In the wild

Organizations and projects using


can list themselves here.



We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.