Dewen Li

A site about Dewen

React - Setup Jest + Enzyme

2021-02-20 Dewen Liweb-development

Create a New React App

npx create-react-app my-app
cd my-app

Install Enzyme

npm i --save-dev enzyme enzyme-adapter-react-16

Configure Jest

edit jest.config.js

module.exports = {
  ...
  setupFilesAfterEnv: ['<rootDir>/config/jestTestSetup'],
  ...
}

edit config/jestTestSetup.js

const enzyme = require("enzyme");
const EnzymeAdapter = require("enzyme-adapter-react-16");

enzyme.configure({ adapter: new EnzymeAdapter() });