Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.69 KB

jest.md

File metadata and controls

50 lines (35 loc) · 1.69 KB

Using Jest with enzyme

Configure with Jest

To run the setup file to configure Enzyme and the Adapter with Jest direct setupTestFrameworkScriptFile to literally the string <rootDir> and the path to your setup file.

{
  "jest": {
    "setupTestFrameworkScriptFile": "<rootDir>src/setupTests.js"
  }
}

Jest version 15 and up

Starting with version 15, Jest no longer mocks modules by default. Because of this, you no longer have to add any special configuration for Jest to use it with enzyme.

Install Jest, and its Babel integrations, as recommended in the Jest docs. Install enzyme. Then, simply require/import React, enzyme functions, and your module at the top of a test file.

import React from 'react';
import { shallow, mount, render } from 'enzyme';

import Foo from '../Foo';

You do not need to include Jest's own renderer, unless you want to use it only for Jest snapshot testing.

Example Project for Jest version 15+

Jest prior to version 15

If you are using Jest 0.9 – 14.0 with enzyme and using Jest's automocking feature, you will need to mark react and enzyme to be unmocked in your package.json:

package.json:

{
  "jest": {
    "unmockedModulePathPatterns": [
      "node_modules/react/",
      "node_modules/enzyme/"
    ]
  }
}

If you are using a previous version of Jest together with npm3, you may need to unmock more modules.