From cd4122d1d0834e6a0eb5252ca847baa573197952 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Mon, 31 Oct 2016 10:51:21 -0500 Subject: [PATCH 1/3] Suggest jest-enzyme for simplifying test matchers --- packages/react-scripts/template/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 788f77e7805..fe84c28855e 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -741,6 +741,12 @@ it('renders welcome message', () => { All Jest matchers are [extensively documented here](http://facebook.github.io/jest/docs/api.html#expect-value).
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) +``` + ### 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). From b99caf767adb42332ba66451b2d01905ac32b837 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Mon, 12 Dec 2016 10:30:47 -0600 Subject: [PATCH 2/3] Update README.md --- packages/react-scripts/template/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index fe84c28855e..e5589a64221 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -747,6 +747,14 @@ Additionally, you might find [jest-enzyme](https://github.com/blainekasten/enzym expect(wrapper).toContainReact(welcome) ``` +To setup jest-enzyme with Create React App, follow the instructions for [`src/setupTests.js`](#srcsetuptestsjs) and 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). From 7b1af6f2e6d744e487eb569e237fc795feaddfd8 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Mon, 12 Dec 2016 10:32:00 -0600 Subject: [PATCH 3/3] Update README.md --- packages/react-scripts/template/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index e5589a64221..0ce7727735f 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -747,7 +747,7 @@ Additionally, you might find [jest-enzyme](https://github.com/blainekasten/enzym expect(wrapper).toContainReact(welcome) ``` -To setup jest-enzyme with Create React App, follow the instructions for [`src/setupTests.js`](#srcsetuptestsjs) and import `jest-enzyme`. +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