npm install --save-dev enzyme enzyme-adapter-react-16
npm install --save-dev chai chai-enzyme@beta
npm install --save-dev sinon sinon-chai
- Create a file called
setupTests.js
insrc
directory. - In
setupTests.js
write:
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
- In your App.test.js file (or whichever component you're testing), add the following:
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow, mount, render } from 'enzyme';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import chai, { expect } from 'chai';
import chaiEnzyme from 'chai-enzyme';
chai.use(chaiEnzyme());
import yourComponentName from './yourComponentFileName'
Required instructions:
https://github.com/producthunt/chai-enzyme#installation
http://airbnb.io/enzyme/docs/guides/mocha.html
Fix issues with chai-enzyme: enzymejs/chai-enzyme#199 enzymejs/chai-enzyme#213
use npm install --save-dev chai-enzyme@beta
in order to work with React 16 and Enzyme 3