diff --git a/docs/Configuration.md b/docs/Configuration.md index 68e3978a6ccb..f0c971fb9c24 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1129,38 +1129,23 @@ Default: `[]` A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since [`setupFiles`](#setupfiles-array) executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment but before the test code itself. -If you want a path to be [relative to the root directory of your project](#rootdir-string), please include `` inside a path's string, like `"/a-configs-folder"`. +In other words, `setupFilesAfterEnv` modules are meant for code which is repeating in each test file. Having the test framework installed makes Jest [globals](GlobalAPI.md), [`jest` object](JestObjectAPI.md) and [`expect`](ExpectAPI.md) accessible in the modules. For example, you can add extra matchers from [`jest-extended`](https://github.com/jest-community/jest-extended) library or call [setup and teardown](SetupAndTeardown.md) hooks: -For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in these modules. +```js title="setup-jest.js" +const matchers = require('jest-extended'); +expect.extend(matchers); -Example `setupFilesAfterEnv` array in a jest.config.js: +afterEach(() => { + jest.useRealTimers(); +}); +``` ```js module.exports = { - setupFilesAfterEnv: ['./jest.setup.js'], + setupFilesAfterEnv: ['/setup-jest.js'], }; ``` -Example `jest.setup.js` file - -```js -jest.setTimeout(10000); // in milliseconds - -// you can even use the setup/teardown methods -beforeAll(() => { - // your code -}); -beforeEach(() => { - // your code -}); -afterEach(() => { - // your code -}); -afterAll(() => { - // your code -}); -``` - ### `slowTestThreshold` \[number] Default: `5` diff --git a/website/versioned_docs/version-25.x/Configuration.md b/website/versioned_docs/version-25.x/Configuration.md index a3c1ee6b0420..f13ea6bf026f 100644 --- a/website/versioned_docs/version-25.x/Configuration.md +++ b/website/versioned_docs/version-25.x/Configuration.md @@ -881,32 +881,31 @@ A list of paths to modules that run some code to configure or set up the testing Default: `[]` -A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since [`setupFiles`](#setupfiles-array) executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment but before the test code itself. +:::tip -If you want a path to be [relative to the root directory of your project](#rootdir-string), please include `` inside a path's string, like `"/a-configs-folder"`. +Renamed from `setupTestFrameworkScriptFile` in Jest 24. -For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in these modules. +::: -:::note +A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since [`setupFiles`](#setupfiles-array) executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment but before the test code itself. -`setupTestFrameworkScriptFile` is deprecated in favor of `setupFilesAfterEnv`. +In other words, `setupFilesAfterEnv` modules are meant for code which is repeating in each test files. Having the test framework installed makes Jest [globals](GlobalAPI.md), [`jest` object](JestObjectAPI.md) and [`expect`](ExpectAPI.md) accessible in the modules. For example, you can add extra matchers from [`jest-extended`](https://github.com/jest-community/jest-extended) library or call [setup and teardown](SetupAndTeardown.md) hooks: -::: +```js title="setup-jest.js" +const matchers = require('jest-extended'); +expect.extend(matchers); -Example `setupFilesAfterEnv` array in a jest.config.js: +afterEach(() => { + jest.useRealTimers(); +}); +``` ```js module.exports = { - setupFilesAfterEnv: ['./jest.setup.js'], + setupFilesAfterEnv: ['/setup-jest.js'], }; ``` -Example `jest.setup.js` file - -```js -jest.setTimeout(10000); // in milliseconds -``` - ### `snapshotResolver` \[string] Default: `undefined` diff --git a/website/versioned_docs/version-26.x/Configuration.md b/website/versioned_docs/version-26.x/Configuration.md index c7d275286a92..13f8dd53e86e 100644 --- a/website/versioned_docs/version-26.x/Configuration.md +++ b/website/versioned_docs/version-26.x/Configuration.md @@ -905,24 +905,23 @@ Default: `[]` A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since [`setupFiles`](#setupfiles-array) executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment but before the test code itself. -If you want a path to be [relative to the root directory of your project](#rootdir-string), please include `` inside a path's string, like `"/a-configs-folder"`. +In other words, `setupFilesAfterEnv` modules are meant for code which is repeating in each test files. Having the test framework installed makes Jest [globals](GlobalAPI.md), [`jest` object](JestObjectAPI.md) and [`expect`](ExpectAPI.md) accessible in the modules. For example, you can add extra matchers from [`jest-extended`](https://github.com/jest-community/jest-extended) library or call [setup and teardown](SetupAndTeardown.md) hooks: -For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in these modules. +```js title="setup-jest.js" +const matchers = require('jest-extended'); +expect.extend(matchers); -Example `setupFilesAfterEnv` array in a jest.config.js: +afterEach(() => { + jest.useRealTimers(); +}); +``` ```js module.exports = { - setupFilesAfterEnv: ['./jest.setup.js'], + setupFilesAfterEnv: ['/setup-jest.js'], }; ``` -Example `jest.setup.js` file - -```js -jest.setTimeout(10000); // in milliseconds -``` - ### `slowTestThreshold` \[number] Default: `5` diff --git a/website/versioned_docs/version-27.x/Configuration.md b/website/versioned_docs/version-27.x/Configuration.md index 8a6ba512dc62..fea8633d90f5 100644 --- a/website/versioned_docs/version-27.x/Configuration.md +++ b/website/versioned_docs/version-27.x/Configuration.md @@ -936,41 +936,23 @@ Default: `[]` A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since [`setupFiles`](#setupfiles-array) executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment but before the test code itself. -If you want a path to be [relative to the root directory of your project](#rootdir-string), please include `` inside a path's string, like `"/a-configs-folder"`. +In other words, `setupFilesAfterEnv` modules are meant for code which is repeating in each test files. Having the test framework installed makes Jest [globals](GlobalAPI.md), [`jest` object](JestObjectAPI.md) and [`expect`](ExpectAPI.md) accessible in the modules. For example, you can add extra matchers from [`jest-extended`](https://github.com/jest-community/jest-extended) library or call [setup and teardown](SetupAndTeardown.md) hooks: -For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in these modules. +```js title="setup-jest.js" +const matchers = require('jest-extended'); +expect.extend(matchers); -Example `setupFilesAfterEnv` array in a jest.config.js: +afterEach(() => { + jest.useRealTimers(); +}); +``` ```js module.exports = { - setupFilesAfterEnv: ['./jest.setup.js'], + setupFilesAfterEnv: ['/setup-jest.js'], }; ``` -Example `jest.setup.js` file - -```js -jest.setTimeout(10000); // in milliseconds - -// you can even use the setup/teardown methods -beforeAll(() => { - // your code -}); - -beforeEach(() => { - // your code -}); - -afterEach(() => { - // your code -}); - -afterAll(() => { - // your code -}); -``` - ### `slowTestThreshold` \[number] Default: `5` diff --git a/website/versioned_docs/version-28.0/Configuration.md b/website/versioned_docs/version-28.0/Configuration.md index 3c4834fa5df2..b1f011944933 100644 --- a/website/versioned_docs/version-28.0/Configuration.md +++ b/website/versioned_docs/version-28.0/Configuration.md @@ -1129,38 +1129,23 @@ Default: `[]` A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since [`setupFiles`](#setupfiles-array) executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment but before the test code itself. -If you want a path to be [relative to the root directory of your project](#rootdir-string), please include `` inside a path's string, like `"/a-configs-folder"`. +In other words, `setupFilesAfterEnv` modules are meant for code which is repeating in each test file. Having the test framework installed makes Jest [globals](GlobalAPI.md), [`jest` object](JestObjectAPI.md) and [`expect`](ExpectAPI.md) accessible in the modules. For example, you can add extra matchers from [`jest-extended`](https://github.com/jest-community/jest-extended) library or call [setup and teardown](SetupAndTeardown.md) hooks: -For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in these modules. +```js title="setup-jest.js" +const matchers = require('jest-extended'); +expect.extend(matchers); -Example `setupFilesAfterEnv` array in a jest.config.js: +afterEach(() => { + jest.useRealTimers(); +}); +``` ```js module.exports = { - setupFilesAfterEnv: ['./jest.setup.js'], + setupFilesAfterEnv: ['/setup-jest.js'], }; ``` -Example `jest.setup.js` file - -```js -jest.setTimeout(10000); // in milliseconds - -// you can even use the setup/teardown methods -beforeAll(() => { - // your code -}); -beforeEach(() => { - // your code -}); -afterEach(() => { - // your code -}); -afterAll(() => { - // your code -}); -``` - ### `slowTestThreshold` \[number] Default: `5` diff --git a/website/versioned_docs/version-28.1/Configuration.md b/website/versioned_docs/version-28.1/Configuration.md index 68e3978a6ccb..f0c971fb9c24 100644 --- a/website/versioned_docs/version-28.1/Configuration.md +++ b/website/versioned_docs/version-28.1/Configuration.md @@ -1129,38 +1129,23 @@ Default: `[]` A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed. Since [`setupFiles`](#setupfiles-array) executes before the test framework is installed in the environment, this script file presents you the opportunity of running some code immediately after the test framework has been installed in the environment but before the test code itself. -If you want a path to be [relative to the root directory of your project](#rootdir-string), please include `` inside a path's string, like `"/a-configs-folder"`. +In other words, `setupFilesAfterEnv` modules are meant for code which is repeating in each test file. Having the test framework installed makes Jest [globals](GlobalAPI.md), [`jest` object](JestObjectAPI.md) and [`expect`](ExpectAPI.md) accessible in the modules. For example, you can add extra matchers from [`jest-extended`](https://github.com/jest-community/jest-extended) library or call [setup and teardown](SetupAndTeardown.md) hooks: -For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in these modules. +```js title="setup-jest.js" +const matchers = require('jest-extended'); +expect.extend(matchers); -Example `setupFilesAfterEnv` array in a jest.config.js: +afterEach(() => { + jest.useRealTimers(); +}); +``` ```js module.exports = { - setupFilesAfterEnv: ['./jest.setup.js'], + setupFilesAfterEnv: ['/setup-jest.js'], }; ``` -Example `jest.setup.js` file - -```js -jest.setTimeout(10000); // in milliseconds - -// you can even use the setup/teardown methods -beforeAll(() => { - // your code -}); -beforeEach(() => { - // your code -}); -afterEach(() => { - // your code -}); -afterAll(() => { - // your code -}); -``` - ### `slowTestThreshold` \[number] Default: `5`