Skip to content

Commit 7239acf

Browse files
Add eslint instructions to getting started (#14562)
1 parent 50fe2ee commit 7239acf

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed

docs/GettingStarted.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,38 @@ npm install --save-dev @types/jest
205205
`@types/jest` is a third party library maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest), hence the latest Jest features or versions may not be covered yet. Try to match versions of Jest and `@types/jest` as closely as possible. For example, if you are using Jest `27.4.0` then installing `27.4.x` of `@types/jest` is ideal.
206206

207207
:::
208+
209+
### Using ESLint
210+
211+
Jest can be used with ESLint without any further configuration as long as you import the [Jest global helpers](GlobalAPI.md) (`describe`, `it`, etc.) from `@jest/globals` before using them in your test file. This is necessary to avoid `no-undef` errors from ESLint, which doesn't know about the Jest globals.
212+
213+
If you'd like to avoid these imports, you can configure your [ESLint environment](https://eslint.org/docs/latest/use/configure/language-options#specifying-environments) to support these globals by adding the `jest` environment:
214+
215+
```json
216+
{
217+
"overrides": [
218+
{
219+
"files": ["tests/**/*"],
220+
"env": {
221+
"jest": true
222+
}
223+
}
224+
]
225+
}
226+
```
227+
228+
Or use [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest), which has a similar effect:
229+
230+
```json
231+
{
232+
"overrides": [
233+
{
234+
"files": ["tests/**/*"],
235+
"plugins": ["jest"],
236+
"env": {
237+
"jest/globals": true
238+
}
239+
}
240+
]
241+
}
242+
```

website/versioned_docs/version-29.4/GettingStarted.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,38 @@ npm install --save-dev @types/jest
205205
`@types/jest` is a third party library maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest), hence the latest Jest features or versions may not be covered yet. Try to match versions of Jest and `@types/jest` as closely as possible. For example, if you are using Jest `27.4.0` then installing `27.4.x` of `@types/jest` is ideal.
206206

207207
:::
208+
209+
### Using ESLint
210+
211+
Jest can be used with ESLint without any further configuration as long as you import the [Jest global helpers](GlobalAPI.md) (`describe`, `it`, etc.) from `@jest/globals` before using them in your test file. This is necessary to avoid `no-undef` errors from ESLint, which doesn't know about the Jest globals.
212+
213+
If you'd like to avoid these imports, you can configure your [ESLint environment](https://eslint.org/docs/latest/use/configure/language-options#specifying-environments) to support these globals by adding the `jest` environment:
214+
215+
```json
216+
{
217+
"overrides": [
218+
{
219+
"files": ["tests/**/*"],
220+
"env": {
221+
"jest": true
222+
}
223+
}
224+
]
225+
}
226+
```
227+
228+
Or use [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest), which has a similar effect:
229+
230+
```json
231+
{
232+
"overrides": [
233+
{
234+
"files": ["tests/**/*"],
235+
"plugins": ["jest"],
236+
"env": {
237+
"jest/globals": true
238+
}
239+
}
240+
]
241+
}
242+
```

website/versioned_docs/version-29.5/GettingStarted.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,38 @@ npm install --save-dev @types/jest
205205
`@types/jest` is a third party library maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest), hence the latest Jest features or versions may not be covered yet. Try to match versions of Jest and `@types/jest` as closely as possible. For example, if you are using Jest `27.4.0` then installing `27.4.x` of `@types/jest` is ideal.
206206

207207
:::
208+
209+
### Using ESLint
210+
211+
Jest can be used with ESLint without any further configuration as long as you import the [Jest global helpers](GlobalAPI.md) (`describe`, `it`, etc.) from `@jest/globals` before using them in your test file. This is necessary to avoid `no-undef` errors from ESLint, which doesn't know about the Jest globals.
212+
213+
If you'd like to avoid these imports, you can configure your [ESLint environment](https://eslint.org/docs/latest/use/configure/language-options#specifying-environments) to support these globals by adding the `jest` environment:
214+
215+
```json
216+
{
217+
"overrides": [
218+
{
219+
"files": ["tests/**/*"],
220+
"env": {
221+
"jest": true
222+
}
223+
}
224+
]
225+
}
226+
```
227+
228+
Or use [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest), which has a similar effect:
229+
230+
```json
231+
{
232+
"overrides": [
233+
{
234+
"files": ["tests/**/*"],
235+
"plugins": ["jest"],
236+
"env": {
237+
"jest/globals": true
238+
}
239+
}
240+
]
241+
}
242+
```

website/versioned_docs/version-29.6/GettingStarted.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,38 @@ npm install --save-dev @types/jest
205205
`@types/jest` is a third party library maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest), hence the latest Jest features or versions may not be covered yet. Try to match versions of Jest and `@types/jest` as closely as possible. For example, if you are using Jest `27.4.0` then installing `27.4.x` of `@types/jest` is ideal.
206206

207207
:::
208+
209+
### Using ESLint
210+
211+
Jest can be used with ESLint without any further configuration as long as you import the [Jest global helpers](GlobalAPI.md) (`describe`, `it`, etc.) from `@jest/globals` before using them in your test file. This is necessary to avoid `no-undef` errors from ESLint, which doesn't know about the Jest globals.
212+
213+
If you'd like to avoid these imports, you can configure your [ESLint environment](https://eslint.org/docs/latest/use/configure/language-options#specifying-environments) to support these globals by adding the `jest` environment:
214+
215+
```json
216+
{
217+
"overrides": [
218+
{
219+
"files": ["tests/**/*"],
220+
"env": {
221+
"jest": true
222+
}
223+
}
224+
]
225+
}
226+
```
227+
228+
Or use [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest), which has a similar effect:
229+
230+
```json
231+
{
232+
"overrides": [
233+
{
234+
"files": ["tests/**/*"],
235+
"plugins": ["jest"],
236+
"env": {
237+
"jest/globals": true
238+
}
239+
}
240+
]
241+
}
242+
```

website/versioned_docs/version-29.7/GettingStarted.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,38 @@ npm install --save-dev @types/jest
205205
`@types/jest` is a third party library maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest), hence the latest Jest features or versions may not be covered yet. Try to match versions of Jest and `@types/jest` as closely as possible. For example, if you are using Jest `27.4.0` then installing `27.4.x` of `@types/jest` is ideal.
206206

207207
:::
208+
209+
### Using ESLint
210+
211+
Jest can be used with ESLint without any further configuration as long as you import the [Jest global helpers](GlobalAPI.md) (`describe`, `it`, etc.) from `@jest/globals` before using them in your test file. This is necessary to avoid `no-undef` errors from ESLint, which doesn't know about the Jest globals.
212+
213+
If you'd like to avoid these imports, you can configure your [ESLint environment](https://eslint.org/docs/latest/use/configure/language-options#specifying-environments) to support these globals by adding the `jest` environment:
214+
215+
```json
216+
{
217+
"overrides": [
218+
{
219+
"files": ["tests/**/*"],
220+
"env": {
221+
"jest": true
222+
}
223+
}
224+
]
225+
}
226+
```
227+
228+
Or use [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest), which has a similar effect:
229+
230+
```json
231+
{
232+
"overrides": [
233+
{
234+
"files": ["tests/**/*"],
235+
"plugins": ["jest"],
236+
"env": {
237+
"jest/globals": true
238+
}
239+
}
240+
]
241+
}
242+
```

0 commit comments

Comments
 (0)