Skip to content

Commit c8b98f0

Browse files
dannycallerigaearon
authored andcommitted
Better documentation for setupTests.js when ejecting (facebook#3656)
* 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. * Added additional note about src/setupTests.js Added another note about src/setupTests.js and `npm run eject` in Testing Components section * Update README.md * Update README.md
1 parent bbf5371 commit c8b98f0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

template/README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ import Adapter from 'enzyme-adapter-react-16';
13341334
configure({ adapter: new Adapter() });
13351335
```
13361336

1337-
(Note that **if you already ejected** before creating `src/setupTests.js`, this won’t work unless you set [this Jest option](https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string) to point to `src/setupTests.js`.)
1337+
>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.
13381338
13391339
Now you can write a smoke test with it:
13401340

@@ -1425,7 +1425,14 @@ const localStorageMock = {
14251425
global.localStorage = localStorageMock
14261426
```
14271427

1428-
Note that **if you already ejected** before creating `src/setupTests.js`, this won’t work unless you set [this Jest option](https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string) to point to `src/setupTests.js`.
1428+
>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:
1429+
1430+
>```js
1431+
>"jest": {
1432+
> // ...
1433+
> "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js"
1434+
> }
1435+
> ```
14291436
14301437
### Focusing and Excluding Tests
14311438

0 commit comments

Comments
 (0)