0 votes
in ReactJS by

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, enzyme-adapter-react-16 has peer dependencies on react and react-dom.

At the moment, Enzyme has adapters that provide compatibility with React 16.x, React 15.x, React 0.14.x and 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

enzyme-adapter-react-16

^16.4.0-0

enzyme-adapter-react-16.3

~16.3.0-0

enzyme-adapter-react-16.2

~16.2

enzyme-adapter-react-16.1

`~16.0.0-0 \

\

~16.1`

enzyme-adapter-react-15

^15.5.0

enzyme-adapter-react-15.4

15.0.0-0 - 15.4.x

enzyme-adapter-react-14

^0.14.0

enzyme-adapter-react-13

^0.13.0

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

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

Related questions

0 votes
asked Mar 20, 2020 in ReactJS by JackTerrance
0 votes
asked Mar 20, 2020 in ReactJS by JackTerrance
0 votes
asked Dec 14, 2019 in ReactJS by AdilsonLima
0 votes
asked Oct 6, 2023 in Service Now by john ganales
0 votes
asked May 31, 2022 in Angular Material by Robin
...