Latest commit 1f3b912 Jun 21, 2018

README.md

jest-enzyme

npm version License

Installation

We suggest using yarn for installations.

yarn add jest-enzyme --dev

But npm works too!

$ npm install jest-enzyme --save-dev

Setup

The simplest setup is to use jest's setupTestFrameworkScriptFile config.

On older versions of Jest, you'll also need to tell jest to unmock react, enzyme, and jest-enzyme.

Make sure your package.json includes the following:

"jest": {
  "setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",

  // old versions of jest set the unmocks
  "unmockedModulePathPatterns": [
    "react",
    "enzyme",
    "jest-enzyme"
  ]
},

Jest Enzyme Environment

There is a special environment to simplify using enzyme with jest. Check it out here

Using with Create React App

If you are using Create React App, instead of adding to your package.json as above, you will need to add a src/setupTests.js file to your app, to import jest-enzyme:

// src/setupTests.js
import 'jest-enzyme';

This is documented on Create React App at the bottom of the Testing Components section. There is also more information about Initializing Test Environment.