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

Add Configure Jest To Run A Test Setup File as a javascript til

This commit is contained in:
jbranchaud
2018-04-23 16:45:28 -05:00
parent a5eee58fd9
commit d58c44cf96
2 changed files with 29 additions and 1 deletions

View File

@@ -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": "<rootDir>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 `<rootDir>`
(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.