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
Copy file name to clipboardExpand all lines: README.md
+65-65
Original file line number
Diff line number
Diff line change
@@ -54,25 +54,25 @@ You can find detailed guides for migrating `eslint-plugin-testing-library` in th
54
54
55
55
## Usage
56
56
57
-
Add `testing-library` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
57
+
Add `testing-library` to the plugins section of your `.eslintrc.js` configuration file. You can omit the `eslint-plugin-` prefix:
58
58
59
-
```json
60
-
{
61
-
"plugins": ["testing-library"]
62
-
}
59
+
```js
60
+
module.exports={
61
+
plugins: ['testing-library'],
62
+
};
63
63
```
64
64
65
65
Then configure the rules you want to use within `rules` property of your `.eslintrc`:
66
66
67
-
```json
68
-
{
69
-
"rules": {
70
-
"testing-library/await-async-query": "error",
71
-
"testing-library/no-await-sync-query": "error",
72
-
"testing-library/no-debugging-utils": "warn",
73
-
"testing-library/no-dom-import": "off"
74
-
}
75
-
}
67
+
```js
68
+
module.exports={
69
+
rules: {
70
+
'testing-library/await-async-query':'error',
71
+
'testing-library/no-await-sync-query':'error',
72
+
'testing-library/no-debugging-utils':'warn',
73
+
'testing-library/no-dom-import':'off',
74
+
},
75
+
};
76
76
```
77
77
78
78
### Run the plugin only against test files
@@ -85,9 +85,9 @@ One way of restricting ESLint config by file patterns is by using [ESLint `overr
85
85
86
86
Assuming you are using the same pattern for your test files as [Jest by default](https://jestjs.io/docs/configuration#testmatch-arraystring), the following config would run `eslint-plugin-testing-library` only against your test files:
87
87
88
-
```json5
89
-
// .eslintrc
90
-
{
88
+
```js
89
+
// .eslintrc.js
90
+
module.exports={
91
91
// 1) Here we have our usual config which applies to the whole project, so we don't put testing-library preset here.
@@ -101,7 +101,7 @@ Assuming you are using the same pattern for your test files as [Jest by default]
101
101
extends: ['plugin:testing-library/react'],
102
102
},
103
103
],
104
-
}
104
+
};
105
105
```
106
106
107
107
#### ESLint Cascading and Hierarchy
@@ -115,83 +115,83 @@ You can find more info about enabled rules in the [Supported Rules section](#sup
115
115
116
116
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:
Enforces recommended rules for DOM Testing Library.
135
135
136
136
To enable this configuration use the `extends` property in your
137
-
`.eslintrc` config file:
137
+
`.eslintrc.js` config file:
138
138
139
-
```json
140
-
{
141
-
"extends": ["plugin:testing-library/dom"]
142
-
}
139
+
```js
140
+
module.exports={
141
+
extends: ['plugin:testing-library/dom'],
142
+
};
143
143
```
144
144
145
145
### Angular
146
146
147
147
Enforces recommended rules for Angular Testing Library.
148
148
149
149
To enable this configuration use the `extends` property in your
150
-
`.eslintrc` config file:
150
+
`.eslintrc.js` config file:
151
151
152
-
```json
153
-
{
154
-
"extends": ["plugin:testing-library/angular"]
155
-
}
152
+
```js
153
+
module.exports={
154
+
extends: ['plugin:testing-library/angular'],
155
+
};
156
156
```
157
157
158
158
### React
159
159
160
160
Enforces recommended rules for React Testing Library.
161
161
162
162
To enable this configuration use the `extends` property in your
163
-
`.eslintrc` config file:
163
+
`.eslintrc.js` config file:
164
164
165
-
```json
166
-
{
167
-
"extends": ["plugin:testing-library/react"]
168
-
}
165
+
```js
166
+
module.exports={
167
+
extends: ['plugin:testing-library/react'],
168
+
};
169
169
```
170
170
171
171
### Vue
172
172
173
173
Enforces recommended rules for Vue Testing Library.
174
174
175
175
To enable this configuration use the `extends` property in your
176
-
`.eslintrc` config file:
176
+
`.eslintrc.js` config file:
177
177
178
-
```json
179
-
{
180
-
"extends": ["plugin:testing-library/vue"]
181
-
}
178
+
```js
179
+
module.exports={
180
+
extends: ['plugin:testing-library/vue'],
181
+
};
182
182
```
183
183
184
184
### Marko
185
185
186
186
Enforces recommended rules for Marko Testing Library.
187
187
188
188
To enable this configuration use the `extends` property in your
189
-
`.eslintrc` config file:
189
+
`.eslintrc.js` config file:
190
190
191
-
```json
192
-
{
193
-
"extends": ["plugin:testing-library/marko"]
194
-
}
191
+
```js
192
+
module.exports={
193
+
extends: ['plugin:testing-library/marko'],
194
+
};
195
195
```
196
196
197
197
## Supported Rules
@@ -251,13 +251,13 @@ If you are sure about configuring the settings, these are the options available:
251
251
252
252
The name of your custom utility file from where you re-export everything from the Testing Library package, or `"off"` to switch related Aggressive Reporting mechanism off. Relates to [Aggressive Imports Reporting](docs/migration-guides/v4.md#imports).
[You can find more details about the `utils-module` setting here](docs/migration-guides/v4.md#testing-libraryutils-module).
@@ -266,13 +266,13 @@ The name of your custom utility file from where you re-export everything from th
266
266
267
267
A list of function names that are valid as Testing Library custom renders, or `"off"` to switch related Aggressive Reporting mechanism off. Relates to [Aggressive Renders Reporting](docs/migration-guides/v4.md#renders).
[You can find more details about the `custom-renders` setting here](docs/migration-guides/v4.md#testing-librarycustom-renders).
@@ -281,13 +281,13 @@ A list of function names that are valid as Testing Library custom renders, or `"
281
281
282
282
A list of query names/patterns that are valid as Testing Library custom queries, or `"off"` to switch related Aggressive Reporting mechanism off. Relates to [Aggressive Reporting - Queries](docs/migration-guides/v4.md#queries)
[You can find more details about the `custom-queries` setting here](docs/migration-guides/v4.md#testing-librarycustom-queries).
@@ -296,15 +296,15 @@ A list of query names/patterns that are valid as Testing Library custom queries,
296
296
297
297
Since each Shared Setting is related to one Aggressive Reporting mechanism, and they accept `"off"` to opt out of that mechanism, you can switch the entire feature off by doing:
Copy file name to clipboardExpand all lines: docs/migration-guides/v4.md
+42-42
Original file line number
Diff line number
Diff line change
@@ -182,13 +182,13 @@ Relates to the [Aggressive Imports Reporting mechanism](#imports). This setting
182
182
183
183
If you pass a string other than `"off"` to this option, it will represent your custom utility file from where you re-export everything from Testing Library package.
Configuring this setting like that, 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:
You can also set this setting to `"off"` to entirely opt-out Aggressive Imports Reporting mechanism, so only utils coming from Testing Library packages are reported.
227
227
228
-
```json
229
-
// .eslintrc
230
-
{
231
-
"settings": {
232
-
"testing-library/utils-module": "off"
233
-
}
234
-
}
228
+
```js
229
+
// .eslintrc.js
230
+
module.exports={
231
+
settings: {
232
+
'testing-library/utils-module':'off',
233
+
},
234
+
};
235
235
```
236
236
237
237
### `testing-library/custom-renders`
@@ -240,13 +240,13 @@ Relates to the [Aggressive Renders Reporting mechanism](#renders). This setting
240
240
241
241
If you pass an array of strings to this option, it will represent a list of function names that are valid as Testing Library custom renders.
Configuring this setting like that, 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:
You can also set this setting to `"off"` to entirely opt-out Aggressive Renders Reporting mechanism, so only methods named `render` are reported as Testing Library render util.
290
290
291
-
```json
292
-
// .eslintrc
293
-
{
294
-
"settings": {
295
-
"testing-library/custom-renders": "off"
296
-
}
297
-
}
291
+
```js
292
+
// .eslintrc.js
293
+
module.exports={
294
+
settings: {
295
+
'testing-library/custom-renders':'off',
296
+
},
297
+
};
298
298
```
299
299
300
300
### `testing-library/custom-queries`
@@ -308,13 +308,13 @@ Each string passed to this list of custom queries can be:
308
308
-**pattern query (recommended)**: a custom query variant (suffix starting with "By") to be reported, so all query combinations around it are reported. For instance: `"ByIcon"` would report all `getByIcon()`, `getAllByIcon()`, `queryByIcon()` and `findByIcon()`.
309
309
-**strict query**: a specific custom query name to be reported, so only that very exact query would be reported but not any related variant. For instance: `"getByIcon"` would make the plugin to report `getByIcon()` but not `getAllByIcon()`, `queryByIcon()` or `findByIcon()`.
Configuring this setting like that, you'll restrict the errors reported by the plugin related to the queries to only those custom queries matching name or pattern from that list, or [built-in queries](https://testing-library.com/docs/queries/about). The previous setting example would cause:
@@ -344,11 +344,11 @@ findBySomethingElse('foo');
344
344
345
345
You can also set this setting to `"off"` to entirely opt-out Aggressive Queries Reporting mechanism, so only built-in queries are reported.
0 commit comments