Skip to content

Commit

Permalink
Suggest jest-enzyme for simplifying test matchers (facebook#994)
Browse files Browse the repository at this point in the history
* Suggest jest-enzyme for simplifying test matchers

* Update README.md

* Update README.md
  • Loading branch information
blainekasten authored and randycoulman committed May 8, 2017
1 parent e28d6ee commit 1193562
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,20 @@ it('renders welcome message', () => {
All Jest matchers are [extensively documented here](http://facebook.github.io/jest/docs/api.html#expect-value).<br>
Nevertheless you can use a third-party assertion library like [Chai](http://chaijs.com/) if you want to, as described below.

Additionally, you might find [jest-enzyme](https://github.com/blainekasten/enzyme-matchers) helpful to simplify your tests with readable matchers. The above `contains` code can be written simpler with jest-enzyme.

```js
expect(wrapper).toContainReact(welcome)
```

To setup jest-enzyme with Create React App, follow the instructions for [initializing your test environment](#initializing-test-environment) to import `jest-enzyme`.

```js
// src/setupTests.js
import 'jest-enzyme';
```


### Using Third Party Assertion Libraries

We recommend that you use `expect()` for assertions and `jest.fn()` for spies. If you are having issues with them please [file those against Jest](https://github.com/facebook/jest/issues/new), and we’ll fix them. We intend to keep making them better for React, supporting, for example, [pretty-printing React elements as JSX](https://github.com/facebook/jest/pull/1566).
Expand Down

0 comments on commit 1193562

Please sign in to comment.