From d58c44cf96d6fd4de079ca6d1b11bf240fa4cc7b Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 23 Apr 2018 16:45:28 -0500 Subject: [PATCH] Add Configure Jest To Run A Test Setup File as a javascript til --- README.md | 3 ++- ...configure-jest-to-run-a-test-setup-file.md | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 javascript/configure-jest-to-run-a-test-setup-file.md diff --git a/README.md b/README.md index f5af010..12756b4 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/). -_670 TILs and counting..._ +_671 TILs and counting..._ --- @@ -229,6 +229,7 @@ _670 TILs and counting..._ - [Character Codes from Keyboard Listeners](javascript/character-codes-from-keyboard-listeners.md) - [Check If Something Is An Array](javascript/check-if-something-is-an-array.md) - [Computed Property Names In ES6](javascript/computed-property-names-in-es6.md) +- [Configure Jest To Run A Test Setup File](javascript/configure-jest-to-run-a-test-setup-file.md) - [Create An Array Containing 1 To N](javascript/create-an-array-containing-1-to-n.md) - [Create Bootstrapped Apps With Yarn](javascript/create-bootstrapped-apps-with-yarn.md) - [Custom Type Checking Error Messages With Yup](javascript/custom-type-checking-error-messages-with-yup.md) diff --git a/javascript/configure-jest-to-run-a-test-setup-file.md b/javascript/configure-jest-to-run-a-test-setup-file.md new file mode 100644 index 0000000..a1fbdce --- /dev/null +++ b/javascript/configure-jest-to-run-a-test-setup-file.md @@ -0,0 +1,27 @@ +# Configure Jest To Run A Test Setup File + +Jest can be configured to run a setup file before each test. This is useful +for configuring your testing framework in a single place, rather than in +each test file. + +This setup file can be specified in `package.json` (or `jest.config.js`). + +```javascript +// package.json +{ + // ... + "jest": { + "setupTestFrameworkScriptFile": "src/setupTests.js" + } +} +``` + +The +[`setupTestFrameworkScriptFile`](https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string) +points to a test setup file at the specified location rooted at `` +(the root of your project). + +This kind of setup is helpful for something like +[Enzyme](https://github.com/airbnb/enzyme/blob/master/docs/guides/jest.md) +that needs to be configured with a specific adapter for use throughout your +tests.