New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documenting how to use enzyme with react 16. Fixes #131. #143

merged 2 commits into from Jul 11, 2018
Jump to file or symbol
Failed to load files and symbols.
+12 −2
Diff settings


Just for now

Copy path View file
@@ -254,16 +254,26 @@ Enzyme is similar, but builds on jsdom and makes it easier to make certain queri
Let's install it as a development-time dependency.
npm install -D enzyme @types/enzyme react-addons-test-utils
npm install -D enzyme @types/enzyme enzyme-adapter-react-16 @types/enzyme-adapter-react-16 react-test-renderer
Notice we installed packages `enzyme` as well as `@types/enzyme`.
The `enzyme` package refers to the package containing JavaScript code that actually gets run, while `@types/enzyme` is a package that contains declaration files (`.d.ts` files) so that TypeScript can understand how you can use Enzyme.
You can learn more about `@types` packages [here](
We also had to install `react-addons-test-utils`.
We also had to install `enzyme-adapter-react-16 and react-test-renderer`.
This is something `enzyme` expects to be installed.
Before writing the first test, we have to configure Enzyme to use an adapter for React 16.
We'll create a file called `src/setupTests.ts` that is automatically loaded when running tests:
import * as enzyme from 'enzyme';
import * as Adapter from 'enzyme-adapter-react-16';
enzyme.configure({ adapter: new Adapter() });
Now that we've got Enzyme set up, let's start writing our test!
Let's create a file named `src/components/Hello.test.tsx`, adjacent to our `Hello.tsx` file from earlier.
ProTip! Use n and p to navigate between commits in a pull request.