From c5dfeda24a06ef8f76c6a3f8e5a73305e2f8fdf1 Mon Sep 17 00:00:00 2001 From: Danny Calleri Date: Thu, 28 Dec 2017 11:32:34 +0100 Subject: [PATCH 1/4] Better documentation for setupTests.js when ejecting When running `npm run eject` before creating `src/setupTests.js`, the resulting `package.json` file, won't contain any entry for it - and this is correct in my opinion, since otherwise Jest will crash - but it's useful to have it documented and avoid pointless waste of time. --- packages/react-scripts/template/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index cbb57d8cdc2..f0a34509d57 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1375,6 +1375,18 @@ const localStorageMock = { global.localStorage = localStorageMock ``` +>Note: Please keep in mind that, if you decide to `npm run eject` before creating `src/setupTests.js`, the resulting package.json file won't contain any reference to it, so you should manually create the property `setupTestFrameworkScriptFile` in the configuration for Jest, something like the following: +>``` +>"jest": { +> ... +> "setupFiles": [ +> "/config/polyfills.js" +> ], +> "setupTestFrameworkScriptFile": "/src/setupTests.js", +> ... +> } +> ``` + ### Focusing and Excluding Tests You can replace `it()` with `xit()` to temporarily exclude a test from being executed.
From 29aee6dd301c1e3980f3d1e7509e5b06b59574a3 Mon Sep 17 00:00:00 2001 From: Danny Calleri Date: Tue, 9 Jan 2018 15:28:21 +0100 Subject: [PATCH 2/4] Added additional note about src/setupTests.js Added another note about src/setupTests.js and `npm run eject` in Testing Components section --- packages/react-scripts/template/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index f0a34509d57..fc23c96008f 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1286,6 +1286,8 @@ import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() }); ``` +>Note: Please keep in mind that, if you decide to `npm run eject` before creating `src/setupTests.js`, the resulting package.json file won't contain any reference to it, [read here](#initializing-test-environment) for a complete description. + Now you can write a smoke test with it: ```js From 65b1a2a806566c2164059311e0e28a14fbb34050 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 9 Jan 2018 15:24:48 +0000 Subject: [PATCH 3/4] Update README.md --- packages/react-scripts/template/README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 871cc39b01a..8b137943acb 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1425,15 +1425,11 @@ const localStorageMock = { global.localStorage = localStorageMock ``` ->Note: Please keep in mind that, if you decide to `npm run eject` before creating `src/setupTests.js`, the resulting package.json file won't contain any reference to it, so you should manually create the property `setupTestFrameworkScriptFile` in the configuration for Jest, something like the following: ->``` +>Note: Keep in mind that if you decide to `npm run eject` before creating `src/setupTests.js`, the resulting `package.json` file won't contain any reference to it, so you should manually create the property `setupTestFrameworkScriptFile` in the configuration for Jest, something like the following: +>```js >"jest": { -> ... -> "setupFiles": [ -> "/config/polyfills.js" -> ], -> "setupTestFrameworkScriptFile": "/src/setupTests.js", -> ... +> // ... +> "setupTestFrameworkScriptFile": "/src/setupTests.js" > } > ``` From a2203ba4fd2d4da908c18d97ce30595ee4a00411 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 9 Jan 2018 15:25:51 +0000 Subject: [PATCH 4/4] Update README.md --- packages/react-scripts/template/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 8b137943acb..548fde096a2 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1334,7 +1334,7 @@ import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() }); ``` ->Note: Please keep in mind that, if you decide to `npm run eject` before creating `src/setupTests.js`, the resulting package.json file won't contain any reference to it, [read here](#initializing-test-environment) for a complete description. +>Note: Keep in mind that if you decide to "eject" before creating `src/setupTests.js`, the resulting `package.json` file won't contain any reference to it. [Read here](#initializing-test-environment) to learn how to add this after ejecting. Now you can write a smoke test with it: @@ -1425,7 +1425,8 @@ const localStorageMock = { global.localStorage = localStorageMock ``` ->Note: Keep in mind that if you decide to `npm run eject` before creating `src/setupTests.js`, the resulting `package.json` file won't contain any reference to it, so you should manually create the property `setupTestFrameworkScriptFile` in the configuration for Jest, something like the following: +>Note: Keep in mind that if you decide to "eject" before creating `src/setupTests.js`, the resulting `package.json` file won't contain any reference to it, so you should manually create the property `setupTestFrameworkScriptFile` in the configuration for Jest, something like the following: + >```js >"jest": { > // ...