Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit b016ad1

Browse files
Merge pull request #143 from catchin/readme-enzyme
Documenting how to use enzyme with react 16. Fixes #131.
2 parents 899c4c8 + 1bd4c71 commit b016ad1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,26 @@ Enzyme is similar, but builds on jsdom and makes it easier to make certain queri
254254
Let's install it as a development-time dependency.
255255

256256
```sh
257-
npm install -D enzyme @types/enzyme react-addons-test-utils
257+
npm install -D enzyme @types/enzyme enzyme-adapter-react-16 @types/enzyme-adapter-react-16 react-test-renderer
258258
```
259259

260260
Notice we installed packages `enzyme` as well as `@types/enzyme`.
261261
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.
262262
You can learn more about `@types` packages [here](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html).
263263

264-
We also had to install `react-addons-test-utils`.
264+
We also had to install `enzyme-adapter-react-16 and react-test-renderer`.
265265
This is something `enzyme` expects to be installed.
266266

267+
Before writing the first test, we have to configure Enzyme to use an adapter for React 16.
268+
We'll create a file called `src/setupTests.ts` that is automatically loaded when running tests:
269+
270+
```ts
271+
import * as enzyme from 'enzyme';
272+
import * as Adapter from 'enzyme-adapter-react-16';
273+
274+
enzyme.configure({ adapter: new Adapter() });
275+
```
276+
267277
Now that we've got Enzyme set up, let's start writing our test!
268278
Let's create a file named `src/components/Hello.test.tsx`, adjacent to our `Hello.tsx` file from earlier.
269279

0 commit comments

Comments
 (0)