Skip to content

Commit 2bd9259

Browse files
blainekastenDaniel Figueiredo
authored and
Daniel Figueiredo
committedFeb 22, 2017
Suggest jest-enzyme for simplifying test matchers (facebook#994)
* Suggest jest-enzyme for simplifying test matchers * Update README.md * Update README.md
1 parent cca16df commit 2bd9259

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎packages/react-scripts/template/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,20 @@ it('renders welcome message', () => {
867867
All Jest matchers are [extensively documented here](http://facebook.github.io/jest/docs/api.html#expect-value).<br>
868868
Nevertheless you can use a third-party assertion library like [Chai](http://chaijs.com/) if you want to, as described below.
869869

870+
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.
871+
872+
```js
873+
expect(wrapper).toContainReact(welcome)
874+
```
875+
876+
To setup jest-enzyme with Create React App, follow the instructions for [initializing your test environment](#initializing-test-environment) to import `jest-enzyme`.
877+
878+
```js
879+
// src/setupTests.js
880+
import 'jest-enzyme';
881+
```
882+
883+
870884
### Using Third Party Assertion Libraries
871885

872886
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).

0 commit comments

Comments
 (0)
Please sign in to comment.