1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add create-react-app Has A Default Test Setup File as a react til

This commit is contained in:
jbranchaud
2018-04-24 17:29:22 -05:00
parent d58c44cf96
commit 07a3884200
2 changed files with 22 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
For a steady stream of TILs from a variety of rocketeers, checkout
[til.hashrocket.com](https://til.hashrocket.com/).
_671 TILs and counting..._
_672 TILs and counting..._
---
@@ -459,6 +459,7 @@ _671 TILs and counting..._
- [Building A React App In The Browser](react/building-a-react-app-in-the-browser.md)
- [Create Dynamically Named Custom React Components](react/create-dynamically-named-custom-react-components.md)
- [create-react-app Comes With Lodash](react/create-react-app-comes-with-lodash.md)
- [create-react-app Has A Default Test Setup File](react/create-react-app-has-a-default-test-setup-file.md)
- [Debug Jest Tests In create-react-app](react/debug-jest-tests-in-create-react-app.md)
- [Defining State In A Simple Class Component](react/defining-state-in-a-simple-class-component.md)
- [Destructure Variables As Props To A Component](react/destructure-variables-as-props-to-a-component.md)

View File

@@ -0,0 +1,20 @@
# create-react-app Has A Default Test Setup File
In [_Configure Jest To Run A Test Setup
File_](https://github.com/jbranchaud/til/blob/master/javascript/configure-jest-to-run-a-test-setup-file.md),
I pointed to a way of configuring Jest in either the `package.json` or
`jest.config.js` file with the `setupTestFrameworkScriptFile` value.
In a `create-react-app` project, this is not an option because
`setupTestFrameworkScriptFile` is not one of the permitted config values for
Jest.
There is a built-in value which happens to match what was recommended in the
above post -- `<rootDir>src/setupTests.js`.
This means that there is no configuration required. Instead, just create a
`setupTests.js` file in the `src` directory of your CRA project and add any
framework setup you need there. That file is already configured to run when
you invoke `yarn test`.
[source](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#initializing-test-environment)