Skip to content

Commit 82ace49

Browse files
authored
refactor: cleanup after migrating all rules to v4 (#303)
* docs: update rule description * test: improve current cases * refactor: use new rule creator * feat: avoid reporting type and keyboard with 0 delay * refactor: use new helpers for detection * test: split fire and user events cases * test: improve errors location asserts * feat: detect user-event import properly * test: add cases for increasing coverage up to 100% * test: assert error message data * test: set final threshold for node-utils * chore: extract semantic release config to its own file * docs: including testing-library prefix in all rules * docs: including testing-library rule prefix in README
1 parent a6eea4d commit 82ace49

28 files changed

+78
-79
lines changed

.releaserc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"pkgRoot": "dist",
3+
"branches": [
4+
"+([0-9])?(.{+([0-9]),x}).x",
5+
"main",
6+
"next",
7+
"next-major",
8+
{
9+
"name": "beta",
10+
"prerelease": true
11+
},
12+
{
13+
"name": "alpha",
14+
"prerelease": true
15+
}
16+
]
17+
}

README.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,32 @@ To enable this configuration use the `extends` property in your
125125

126126
## Supported Rules
127127

128-
| Rule | Description | Configurations | Fixable |
129-
| -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------ |
130-
| [await-async-query](docs/rules/await-async-query.md) | Enforce promises from async queries to be handled | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
131-
| [await-async-utils](docs/rules/await-async-utils.md) | Enforce async utils to be awaited properly | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
132-
| [await-fire-event](docs/rules/await-fire-event.md) | Enforce promises from fire event methods to be handled | ![vue-badge][] | |
133-
| [consistent-data-testid](docs/rules/consistent-data-testid.md) | Ensure `data-testid` values match a provided regex. | | |
134-
| [no-await-sync-events](docs/rules/no-await-sync-events.md) | Disallow unnecessary `await` for sync events | | |
135-
| [no-await-sync-query](docs/rules/no-await-sync-query.md) | Disallow unnecessary `await` for sync queries | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
136-
| [no-container](docs/rules/no-container.md) | Disallow the use of `container` methods | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
137-
| [no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
138-
| [no-dom-import](docs/rules/no-dom-import.md) | Disallow importing from DOM Testing Library | ![angular-badge][] ![react-badge][] ![vue-badge][] | ![fixable-badge][] |
139-
| [no-manual-cleanup](docs/rules/no-manual-cleanup.md) | Disallow the use of `cleanup` | | |
140-
| [no-node-access](docs/rules/no-node-access.md) | Disallow direct Node access | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
141-
| [no-promise-in-fire-event](docs/rules/no-promise-in-fire-event.md) | Disallow the use of promises passed to a `fireEvent` method | | |
142-
| [no-render-in-setup](docs/rules/no-render-in-setup.md) | Disallow the use of `render` in setup functions | | |
143-
| [no-wait-for-empty-callback](docs/rules/no-wait-for-empty-callback.md) | Disallow empty callbacks for `waitFor` and `waitForElementToBeRemoved` | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
144-
| [no-wait-for-multiple-assertions](docs/rules/no-wait-for-multiple-assertions.md) | Disallow the use of multiple expect inside `waitFor` | | |
145-
| [no-wait-for-side-effects](docs/rules/no-wait-for-side-effects.md) | Disallow the use of side effects inside `waitFor` | | |
146-
| [no-wait-for-snapshot](docs/rules/no-wait-for-snapshot.md) | Ensures no snapshot is generated inside of a `waitFor` call | | |
147-
| [prefer-explicit-assert](docs/rules/prefer-explicit-assert.md) | Suggest using explicit assertions rather than just `getBy*` queries | | |
148-
| [prefer-find-by](docs/rules/prefer-find-by.md) | Suggest using `findBy*` methods instead of the `waitFor` + `getBy` queries | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | ![fixable-badge][] |
149-
| [prefer-presence-queries](docs/rules/prefer-presence-queries.md) | Enforce specific queries when checking element is present or not | | |
150-
| [prefer-user-event](docs/rules/prefer-user-event.md) | Suggest using `userEvent` library instead of `fireEvent` for simulating user interaction | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
151-
| [prefer-screen-queries](docs/rules/prefer-screen-queries.md) | Suggest using screen while using queries | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
152-
| [prefer-wait-for](docs/rules/prefer-wait-for.md) | Use `waitFor` instead of deprecated wait methods | | ![fixable-badge][] |
153-
| [render-result-naming-convention](docs/rules/render-result-naming-convention.md) | Enforce a valid naming for return value from `render` | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
128+
| Rule | Description | Configurations | Fixable |
129+
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------ |
130+
| [testing-library/await-async-query](docs/rules/await-async-query.md) | Enforce promises from async queries to be handled | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
131+
| [testing-library/await-async-utils](docs/rules/await-async-utils.md) | Enforce async utils to be awaited properly | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
132+
| [testing-library/await-fire-event](docs/rules/await-fire-event.md) | Enforce promises from fire event methods to be handled | ![vue-badge][] | |
133+
| [testing-library/consistent-data-testid](docs/rules/consistent-data-testid.md) | Ensure `data-testid` values match a provided regex. | | |
134+
| [testing-library/no-await-sync-events](docs/rules/no-await-sync-events.md) | Disallow unnecessary `await` for sync events | | |
135+
| [testing-library/no-await-sync-query](docs/rules/no-await-sync-query.md) | Disallow unnecessary `await` for sync queries | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
136+
| [testing-library/no-container](docs/rules/no-container.md) | Disallow the use of `container` methods | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
137+
| [testing-library/no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
138+
| [testing-library/no-dom-import](docs/rules/no-dom-import.md) | Disallow importing from DOM Testing Library | ![angular-badge][] ![react-badge][] ![vue-badge][] | ![fixable-badge][] |
139+
| [testing-library/no-manual-cleanup](docs/rules/no-manual-cleanup.md) | Disallow the use of `cleanup` | | |
140+
| [testing-library/no-node-access](docs/rules/no-node-access.md) | Disallow direct Node access | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
141+
| [testing-library/no-promise-in-fire-event](docs/rules/no-promise-in-fire-event.md) | Disallow the use of promises passed to a `fireEvent` method | | |
142+
| [testing-library/no-render-in-setup](docs/rules/no-render-in-setup.md) | Disallow the use of `render` in setup functions | | |
143+
| [testing-library/no-wait-for-empty-callback](docs/rules/no-wait-for-empty-callback.md) | Disallow empty callbacks for `waitFor` and `waitForElementToBeRemoved` | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
144+
| [testing-library/no-wait-for-multiple-assertions](docs/rules/no-wait-for-multiple-assertions.md) | Disallow the use of multiple expect inside `waitFor` | | |
145+
| [testing-library/no-wait-for-side-effects](docs/rules/no-wait-for-side-effects.md) | Disallow the use of side effects inside `waitFor` | | |
146+
| [testing-library/no-wait-for-snapshot](docs/rules/no-wait-for-snapshot.md) | Ensures no snapshot is generated inside of a `waitFor` call | | |
147+
| [testing-library/prefer-explicit-assert](docs/rules/prefer-explicit-assert.md) | Suggest using explicit assertions rather than just `getBy*` queries | | |
148+
| [testing-library/prefer-find-by](docs/rules/prefer-find-by.md) | Suggest using `findBy*` methods instead of the `waitFor` + `getBy` queries | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | ![fixable-badge][] |
149+
| [testing-library/prefer-presence-queries](docs/rules/prefer-presence-queries.md) | Enforce specific queries when checking element is present or not | | |
150+
| [testing-library/prefer-user-event](docs/rules/prefer-user-event.md) | Suggest using `userEvent` library instead of `fireEvent` for simulating user interaction | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
151+
| [testing-library/prefer-screen-queries](docs/rules/prefer-screen-queries.md) | Suggest using screen while using queries | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
152+
| [testing-library/prefer-wait-for](docs/rules/prefer-wait-for.md) | Use `waitFor` instead of deprecated wait methods | | ![fixable-badge][] |
153+
| [testing-library/render-result-naming-convention](docs/rules/render-result-naming-convention.md) | Enforce a valid naming for return value from `render` | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
154154

155155
[build-badge]: https://github.com/testing-library/eslint-plugin-testing-library/actions/workflows/pipeline.yml/badge.svg
156156
[build-url]: https://github.com/testing-library/eslint-plugin-testing-library/actions/workflows/pipeline.yml

docs/rules/await-async-query.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Enforce promises from async queries to be handled (await-async-query)
1+
# Enforce promises from async queries to be handled (`testing-library/await-async-query`)
22

33
Ensure that promises returned by async queries are handled properly.
44

docs/rules/await-async-utils.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Enforce promises from async utils to be handled (await-async-utils)
1+
# Enforce promises from async utils to be handled (`testing-library/await-async-utils`)
22

33
Ensure that promises returned by async utils are handled properly.
44

docs/rules/await-fire-event.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Enforce promises from fire event methods to be handled (await-fire-event)
1+
# Enforce promises from fire event methods to be handled (`testing-library/await-fire-event`)
22

33
Ensure that promises returned by `fireEvent` methods are handled
44
properly.

docs/rules/consistent-data-testid.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Enforces consistent naming for the data-testid attribute (consistent-data-testid)
1+
# Enforces consistent naming for the data-testid attribute (`testing-library/consistent-data-testid`)
22

33
Ensure `data-testid` values match a provided regex. This rule is un-opinionated, and requires configuration.
44

docs/rules/no-await-sync-events.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow unnecessary `await` for sync events (no-await-sync-events)
1+
# Disallow unnecessary `await` for sync events (`testing-library/no-await-sync-events`)
22

33
Ensure that sync simulated events are not awaited unnecessarily.
44

docs/rules/no-await-sync-query.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow unnecessary `await` for sync queries (no-await-sync-query)
1+
# Disallow unnecessary `await` for sync queries (`testing-library/no-await-sync-query`)
22

33
Ensure that sync queries are not awaited unnecessarily.
44

docs/rules/no-container.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow the use of `container` methods (no-container)
1+
# Disallow the use of `container` methods (`testing-library/no-container`)
22

33
By using `container` methods like `.querySelector` you may lose a lot of the confidence that the user can really interact with your UI. Also, the test becomes harder to read, and it will break more frequently.
44

docs/rules/no-debug.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow the use of `debug` (no-debug)
1+
# Disallow the use of `debug` (`testing-library/no-debug`)
22

33
Just like `console.log` statements pollutes the browser's output, debug statements also pollutes the tests if one of your teammates forgot to remove it. `debug` statements should be used when you actually want to debug your tests but should not be pushed to the codebase.
44

docs/rules/no-dom-import.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow importing from DOM Testing Library
1+
# Disallow importing from DOM Testing Library (`testing-library/no-dom-import`)
22

33
Ensure that there are no direct imports from `@testing-library/dom` or
44
`dom-testing-library` when using some testing library framework
@@ -7,18 +7,18 @@ wrapper.
77
## Rule Details
88

99
Testing Library framework wrappers as React Testing Library already
10-
re-exports everything from DOM Testing Library so you always have to
11-
import DOM Testing Library utils from corresponding framework wrapper
10+
re-exports everything from DOM Testing Library, so you always have to
11+
import Testing Library utils from corresponding framework wrapper
1212
module to:
1313

1414
- use proper extended version of some of those methods containing
1515
additional functionality related to specific framework (e.g.
1616
`fireEvent` util)
1717
- avoid importing from extraneous dependencies (similar to
18-
eslint-plugin-import)
18+
`eslint-plugin-import`)
1919

2020
This rule aims to prevent users from import anything directly from
21-
`@testing-library/dom` (or `dom-testing-library`) and it's useful for
21+
`@testing-library/dom`, which is useful for
2222
new starters or when IDEs autoimport from wrong module.
2323

2424
Examples of **incorrect** code for this rule:

docs/rules/no-manual-cleanup.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow the use of `cleanup` (no-manual-cleanup)
1+
# Disallow the use of `cleanup` (`testing-library/no-manual-cleanup`)
22

33
`cleanup` is performed automatically if the testing framework you're using supports the `afterEach` global (like mocha, Jest, and Jasmine). In this case, it's unnecessary to do manual cleanups after each test unless you skip the auto-cleanup with environment variables such as `RTL_SKIP_AUTO_CLEANUP` for React.
44

docs/rules/no-node-access.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow direct Node access (no-node-access)
1+
# Disallow direct Node access (`testing-library/no-node-access`)
22

33
The Testing Library already provides methods for querying DOM elements.
44

docs/rules/no-promise-in-fire-event.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow the use of promises passed to a `fireEvent` method (no-promise-in-fire-event)
1+
# Disallow the use of promises passed to a `fireEvent` method (`testing-library/no-promise-in-fire-event`)
22

33
Methods from `fireEvent` expect to receive a DOM element. Passing a promise will end up in an error, so it must be prevented.
44

docs/rules/no-render-in-setup.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Disallow the use of `render` in setup functions (no-render-in-setup)
1+
# Disallow the use of `render` in setup functions (`testing-library/no-render-in-setup`)
22

33
## Rule Details
44

docs/rules/no-wait-for-empty-callback.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Empty callbacks inside `waitFor` and `waitForElementToBeRemoved` are not preferred (no-wait-for-empty-callback)
1+
# Empty callbacks inside `waitFor` and `waitForElementToBeRemoved` are not preferred (`testing-library/no-wait-for-empty-callback`)
22

33
## Rule Details
44

docs/rules/no-wait-for-multiple-assertions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Multiple assertions inside `waitFor` are not preferred (no-wait-for-multiple-assertions)
1+
# Disallow the use of multiple expect inside `waitFor` (`testing-library/no-wait-for-multiple-assertions`)
22

33
## Rule Details
44

docs/rules/no-wait-for-side-effects.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Side effects inside `waitFor` are not preferred (no-wait-for-side-effects)
1+
# Disallow the use of side effects inside `waitFor` (`testing-library/no-wait-for-side-effects`)
22

33
## Rule Details
44

0 commit comments

Comments
 (0)