diff --git a/README.md b/README.md index 12756b4..c14c01a 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/react/create-react-app-has-a-default-test-setup-file.md b/react/create-react-app-has-a-default-test-setup-file.md new file mode 100644 index 0000000..bff1c8a --- /dev/null +++ b/react/create-react-app-has-a-default-test-setup-file.md @@ -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 -- `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)