Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 1.72 KB

README.md

File metadata and controls

52 lines (36 loc) · 1.72 KB

jest-enzyme

npm version License Circle CI

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"
  ]
},

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.