Skip to content

Commit

Permalink
docs: add testEnvironmentOptions configuration examples (#13991)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas authored Mar 8, 2023
1 parent 39f3bed commit 67aa05c
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 11 deletions.
56 changes: 55 additions & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1908,10 +1908,64 @@ Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "<html lang="zh-cmn-Hant"></html>", url: 'https://jestjs.io/', userAgent: "Agent/007"}`.
For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

export default config;
```

Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`.

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

export default config;
```

These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`:

```js
Expand Down
14 changes: 13 additions & 1 deletion website/versioned_docs/version-25.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,19 @@ beforeAll(() => {

Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. For example, you can override options given to [jsdom](https://github.com/jsdom/jsdom) such as `{userAgent: "Agent/007"}`.
Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js
module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
userAgent: 'Agent/007',
},
};
```

### `testFailureExitCode` \[number]

Expand Down
14 changes: 13 additions & 1 deletion website/versioned_docs/version-26.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,19 @@ beforeAll(() => {

Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. For example, you can override options given to [jsdom](https://github.com/jsdom/jsdom) such as `{userAgent: "Agent/007"}`.
Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js
module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
userAgent: 'Agent/007',
},
};
```

### `testFailureExitCode` \[number]

Expand Down
14 changes: 13 additions & 1 deletion website/versioned_docs/version-27.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,19 @@ beforeAll(() => {

Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. For example, you can override options given to [jsdom](https://github.com/jsdom/jsdom) such as `{html: "<html lang="zh-cmn-Hant"></html>", userAgent: "Agent/007"}`.
Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js
module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
userAgent: 'Agent/007',
},
};
```

### `testFailureExitCode` \[number]

Expand Down
22 changes: 21 additions & 1 deletion website/versioned_docs/version-28.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1393,10 +1393,30 @@ Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "<html lang="zh-cmn-Hant"></html>", url: 'https://jestjs.io/', userAgent: "Agent/007"}`.
For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js
module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};
```

Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`.

```js
module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};
```

These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`:

```js
Expand Down
56 changes: 55 additions & 1 deletion website/versioned_docs/version-29.0/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1867,10 +1867,64 @@ Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "<html lang="zh-cmn-Hant"></html>", url: 'https://jestjs.io/', userAgent: "Agent/007"}`.
For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

export default config;
```

Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`.

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

export default config;
```

These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`:

```js
Expand Down
56 changes: 55 additions & 1 deletion website/versioned_docs/version-29.1/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1867,10 +1867,64 @@ Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "<html lang="zh-cmn-Hant"></html>", url: 'https://jestjs.io/', userAgent: "Agent/007"}`.
For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

export default config;
```

Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`.

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

export default config;
```

These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`:

```js
Expand Down
56 changes: 55 additions & 1 deletion website/versioned_docs/version-29.2/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,64 @@ Default: `{}`

Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment.

For example, in `jest-environment-jsdom`, you can override options given to [`jsdom`](https://github.com/jsdom/jsdom) such as `{html: "<html lang="zh-cmn-Hant"></html>", url: 'https://jestjs.io/', userAgent: "Agent/007"}`.
For example, you can override options passed to [`jsdom`](https://github.com/jsdom/jsdom):

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: '<html lang="zh-cmn-Hant"></html>',
url: 'https://jestjs.io/',
userAgent: 'Agent/007',
},
};

export default config;
```

Both `jest-environment-jsdom` and `jest-environment-node` allow specifying `customExportConditions`, which allow you to control which versions of a library are loaded from `exports` in `package.json`. `jest-environment-jsdom` defaults to `['browser']`. `jest-environment-node` defaults to `['node', 'node-addons']`.

```js tab
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['react-native'],
},
};

export default config;
```

These options can also be passed in a docblock, similar to `testEnvironment`. The string with options must be parseable by `JSON.parse`:

```js
Expand Down
Loading

0 comments on commit 67aa05c

Please sign in to comment.