You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-testing-library` globally.
46
50
51
+
## Migrating to v4
52
+
53
+
You can find [here a detailed guide for migrating `eslint-plugin-testing-library` to v4](docs/migrating-to-v4-guide.md).
54
+
47
55
## Usage
48
56
49
57
Add `testing-library` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
@@ -54,22 +62,37 @@ Add `testing-library` to the plugins section of your `.eslintrc` configuration f
54
62
}
55
63
```
56
64
57
-
Then configure the rules you want to use under the rules section.
65
+
Then configure the rules you want to use within `rules` property of your `.eslintrc`:
58
66
59
67
```json
60
68
{
61
69
"rules": {
62
70
"testing-library/await-async-query": "error",
63
71
"testing-library/no-await-sync-query": "error",
64
-
"testing-library/no-debug": "warn"
72
+
"testing-library/no-debug": "warn",
73
+
"testing-library/no-dom-import": "off"
65
74
}
66
75
}
67
76
```
68
77
69
78
## Shareable configurations
70
79
71
80
This plugin exports several recommended configurations that enforce good practices for specific Testing Library packages.
72
-
You can find more info about enabled rules in the [Supported Rules section](#supported-rules) within the `Configurations` column.
81
+
You can find more info about enabled rules in the [Supported Rules section](#supported-rules), under the `Configurations` column.
82
+
83
+
Since each one of these configurations is aimed at a particular Testing Library package, they are not extendable between them, so you should use only one of them at once per `eslintrc` file. For example, if you want to enable recommended configuration for React, you don't need to combine it somehow with DOM one:
There are some configuration options available that will be shared across all the plugin rules. This is achieved using [ESLint Shared Settings](https://eslint.org/docs/user-guide/configuring/configuration-files#adding-shared-settings). These Shared Settings are meant to be used if you need to restrict the Aggressive Reporting mechanism, which is an out of the box advanced feature to lint Testing Library usages in a simpler way for most of the users. **So please before configuring any of these settings**, read more about [the advantages of `eslint-plugin-testing-library` Aggressive Reporting mechanism](docs/migrating-to-v4-guide.md#aggressive-reporting), and [how it's affected by these settings](docs/migrating-to-v4-guide.md#shared-settings).
201
+
202
+
If you are sure about configuring the settings, these are the options available:
203
+
204
+
### `testing-library/utils-module`
205
+
206
+
The name of your custom utility file from where you re-export everything from Testing Library package.
[You can find more details here](docs/migrating-to-v4-guide.md#testing-libraryutils-module).
218
+
219
+
### `testing-library/custom-renders`
220
+
221
+
A list of function names that are valid as Testing Library custom renders. Relates to [Aggressive Reporting - Renders](docs/migrating-to-v4-guide.md#renders)
Copy file name to clipboardExpand all lines: docs/migrating-to-v4-guide.md
+74-9Lines changed: 74 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -153,13 +153,13 @@ _You can find the motivation behind this behavior on [this issue comment](https:
153
153
154
154
By default, `eslint-plugin-testing-library` v4 won't check from which module are the utils imported. This means it doesn't matter if you are importing the utils from `@testing-library/*`, `test-utils` or `whatever`.
155
155
156
-
There is a new Shared Setting to restrict this scope though: [`utils-module`](#utils-module). By using this setting, only utils imported from `@testing-library/*` packages, or the custom one indicated in this setting would be reported.
156
+
There is a new Shared Setting to restrict this scope though: [`utils-module`](#testing-libraryutils-module). By using this setting, only utils imported from `@testing-library/*` packages, or the custom one indicated in this setting would be reported.
157
157
158
158
### Renders
159
159
160
160
By default, `eslint-plugin-testing-library` v4 will assume that all methods which names contain "render" should be reported. This means it doesn't matter if you are rendering your elements for testing using `render`, `customRender` or `renderWithRedux`.
161
161
162
-
There is a new Shared Setting to restrict this scope though: [`custom-renders`](#custom-renders). By using this setting, only methods strictly named `render` or as one of the indicated Custom Renders would be reported.
162
+
There is a new Shared Setting to restrict this scope though: [`custom-renders`](#testing-librarycustom-renders). By using this setting, only methods strictly named `render` or as one of the indicated Custom Renders would be reported.
163
163
164
164
### Queries
165
165
@@ -175,24 +175,54 @@ To avoid collision with settings from other ESLint plugins, all the properties f
175
175
176
176
⚠️ **Please be aware of using these settings will disable part of [Aggressive Reporting](#aggressive-reporting).**
177
177
178
-
### `utils-module`
178
+
### `testing-library/utils-module`
179
179
180
-
Relates to [Aggressive Reporting - Imports](#imports). This setting (just a string) allows you to indicate which is the only Custom Module you'd like to be reported by `eslint-plugin-testing-library`.
180
+
The name of your custom utility file from where you re-export everything from Testing Library package. Relates to [Aggressive Reporting - Imports](#imports).
The previous setting example would force `eslint-plugin-testing-library` to only report Testing Library utils coming from `@testing-library/*` package or `my-custom-test-utils`, silencing potential errors for utils imported from somewhere else.
191
+
Enabling this setting, you'll restrict the errors reported by the plugin to only those utils being imported from this custom utility file, or some `@testing-library/*` package. The previous setting example would cause:
// ✅ this would be reported since this invalid usage of an util
208
+
// is imported from specified custom utility file.
209
+
waitFor(/* some invalid usage to be reported */);
210
+
});
211
+
```
194
212
195
-
Relates to [Aggressive Reporting - Renders](#renders). This setting (array of strings) allows you to indicate which are the only Custom Renders you'd like to be reported by `eslint-plugin-testing-library`.
// ❌ this would NOT be reported since this invalid usage of an util
218
+
// is NOT imported from either `@testing-library/*` package or specified custom utility file.
219
+
waitFor(/* some invalid usage to be reported */);
220
+
});
221
+
```
222
+
223
+
### `testing-library/custom-renders`
224
+
225
+
A list of function names that are valid as Testing Library custom renders. Relates to [Aggressive Reporting - Renders](#renders)
196
226
197
227
```json
198
228
// .eslintrc
@@ -203,4 +233,39 @@ Relates to [Aggressive Reporting - Renders](#renders). This setting (array of st
203
233
}
204
234
```
205
235
206
-
The previous setting example would force `eslint-plugin-testing-library` to only report Testing Library renders named `render` (built-in one is always included), `display` and `renderWithProviders`, silencing potential errors for others custom renders.
236
+
Enabling this setting, you'll restrict the errors reported by the plugin related to `render` somehow to only those functions sharing a name with one of the elements of that list, or built-in `render`. The previous setting example would cause:
0 commit comments