Edit This Page

Using Jest with Enzyme

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.

Example Project for Jest prior to version 15