Skip to content

Commit

Permalink
docs: improve setupFilesAfterEnv documentation (#12846)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed May 15, 2022
1 parent 39bad8c commit 3f78547
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 123 deletions.
33 changes: 9 additions & 24 deletions docs/Configuration.md
Expand Up @@ -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 `<rootDir>` inside a path's string, like `"<rootDir>/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: ['<rootDir>/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`
Expand Down
27 changes: 13 additions & 14 deletions website/versioned_docs/version-25.x/Configuration.md
Expand Up @@ -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 `<rootDir>` inside a path's string, like `"<rootDir>/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: ['<rootDir>/setup-jest.js'],
};
```

Example `jest.setup.js` file

```js
jest.setTimeout(10000); // in milliseconds
```

### `snapshotResolver` \[string]

Default: `undefined`
Expand Down
19 changes: 9 additions & 10 deletions website/versioned_docs/version-26.x/Configuration.md
Expand Up @@ -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 `<rootDir>` inside a path's string, like `"<rootDir>/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: ['<rootDir>/setup-jest.js'],
};
```

Example `jest.setup.js` file

```js
jest.setTimeout(10000); // in milliseconds
```

### `slowTestThreshold` \[number]

Default: `5`
Expand Down
36 changes: 9 additions & 27 deletions website/versioned_docs/version-27.x/Configuration.md
Expand Up @@ -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 `<rootDir>` inside a path's string, like `"<rootDir>/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: ['<rootDir>/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`
Expand Down
33 changes: 9 additions & 24 deletions website/versioned_docs/version-28.0/Configuration.md
Expand Up @@ -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 `<rootDir>` inside a path's string, like `"<rootDir>/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: ['<rootDir>/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`
Expand Down
33 changes: 9 additions & 24 deletions website/versioned_docs/version-28.1/Configuration.md
Expand Up @@ -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 `<rootDir>` inside a path's string, like `"<rootDir>/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: ['<rootDir>/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`
Expand Down

0 comments on commit 3f78547

Please sign in to comment.