mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add create-react-app Has A Default Test Setup File as a react til
This commit is contained in:
20
react/create-react-app-has-a-default-test-setup-file.md
Normal file
20
react/create-react-app-has-a-default-test-setup-file.md
Normal 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)
|
||||
Reference in New Issue
Block a user