We suggest using yarn for installations.
yarn add jest-environment-enzyme --dev
But npm works too!
$ npm install jest-environment-enzyme --save-dev
With this library, you don't need to have your app install Enzyme, but you have to install one of Enzymes adapters.
yarn add enzyme-adapter-* --dev
Where *
is your app's adapter.
Set the testEnvironment
to enzyme
in your package.json
.
"jest": {
"setupTestFrameworkScriptFile": "jest-enzyme",
"testEnvironment": "enzyme",
},
Additionally, you can specify which enzyme adapter you want to use through the testEnvironmentOptions.enzymeAdapter
.
Valid options are:
react13
react14
react15
react15.4
react16
(default)
// package.json
"jest": {
"setupTestFrameworkScriptFile": "jest-enzyme",
"testEnvironment": "enzyme",
"testEnvironmentOptions": {
"enzymeAdapter": "react16"
}
}
Lastly, and most importantly, this library has a hard requirement on jest-enzyme
.