Skip to content

refactor: cleanup after migrating all rules to v4 #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"pkgRoot": "dist",
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
]
}
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -125,32 +125,32 @@ To enable this configuration use the `extends` property in your

## Supported Rules

| Rule | Description | Configurations | Fixable |
| -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------ |
| [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][] | |
| [await-async-utils](docs/rules/await-async-utils.md) | Enforce async utils to be awaited properly | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [await-fire-event](docs/rules/await-fire-event.md) | Enforce promises from fire event methods to be handled | ![vue-badge][] | |
| [consistent-data-testid](docs/rules/consistent-data-testid.md) | Ensure `data-testid` values match a provided regex. | | |
| [no-await-sync-events](docs/rules/no-await-sync-events.md) | Disallow unnecessary `await` for sync events | | |
| [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][] | |
| [no-container](docs/rules/no-container.md) | Disallow the use of `container` methods | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [no-dom-import](docs/rules/no-dom-import.md) | Disallow importing from DOM Testing Library | ![angular-badge][] ![react-badge][] ![vue-badge][] | ![fixable-badge][] |
| [no-manual-cleanup](docs/rules/no-manual-cleanup.md) | Disallow the use of `cleanup` | | |
| [no-node-access](docs/rules/no-node-access.md) | Disallow direct Node access | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [no-promise-in-fire-event](docs/rules/no-promise-in-fire-event.md) | Disallow the use of promises passed to a `fireEvent` method | | |
| [no-render-in-setup](docs/rules/no-render-in-setup.md) | Disallow the use of `render` in setup functions | | |
| [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][] | |
| [no-wait-for-multiple-assertions](docs/rules/no-wait-for-multiple-assertions.md) | Disallow the use of multiple expect inside `waitFor` | | |
| [no-wait-for-side-effects](docs/rules/no-wait-for-side-effects.md) | Disallow the use of side effects inside `waitFor` | | |
| [no-wait-for-snapshot](docs/rules/no-wait-for-snapshot.md) | Ensures no snapshot is generated inside of a `waitFor` call | | |
| [prefer-explicit-assert](docs/rules/prefer-explicit-assert.md) | Suggest using explicit assertions rather than just `getBy*` queries | | |
| [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][] |
| [prefer-presence-queries](docs/rules/prefer-presence-queries.md) | Enforce specific queries when checking element is present or not | | |
| [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][] | |
| [prefer-screen-queries](docs/rules/prefer-screen-queries.md) | Suggest using screen while using queries | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [prefer-wait-for](docs/rules/prefer-wait-for.md) | Use `waitFor` instead of deprecated wait methods | | ![fixable-badge][] |
| [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][] | |
| Rule | Description | Configurations | Fixable |
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------ |
| [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][] | |
| [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][] | |
| [testing-library/await-fire-event](docs/rules/await-fire-event.md) | Enforce promises from fire event methods to be handled | ![vue-badge][] | |
| [testing-library/consistent-data-testid](docs/rules/consistent-data-testid.md) | Ensure `data-testid` values match a provided regex. | | |
| [testing-library/no-await-sync-events](docs/rules/no-await-sync-events.md) | Disallow unnecessary `await` for sync events | | |
| [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][] | |
| [testing-library/no-container](docs/rules/no-container.md) | Disallow the use of `container` methods | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [testing-library/no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [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][] |
| [testing-library/no-manual-cleanup](docs/rules/no-manual-cleanup.md) | Disallow the use of `cleanup` | | |
| [testing-library/no-node-access](docs/rules/no-node-access.md) | Disallow direct Node access | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [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 | | |
| [testing-library/no-render-in-setup](docs/rules/no-render-in-setup.md) | Disallow the use of `render` in setup functions | | |
| [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][] | |
| [testing-library/no-wait-for-multiple-assertions](docs/rules/no-wait-for-multiple-assertions.md) | Disallow the use of multiple expect inside `waitFor` | | |
| [testing-library/no-wait-for-side-effects](docs/rules/no-wait-for-side-effects.md) | Disallow the use of side effects inside `waitFor` | | |
| [testing-library/no-wait-for-snapshot](docs/rules/no-wait-for-snapshot.md) | Ensures no snapshot is generated inside of a `waitFor` call | | |
| [testing-library/prefer-explicit-assert](docs/rules/prefer-explicit-assert.md) | Suggest using explicit assertions rather than just `getBy*` queries | | |
| [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][] |
| [testing-library/prefer-presence-queries](docs/rules/prefer-presence-queries.md) | Enforce specific queries when checking element is present or not | | |
| [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][] | |
| [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][] | |
| [testing-library/prefer-wait-for](docs/rules/prefer-wait-for.md) | Use `waitFor` instead of deprecated wait methods | | ![fixable-badge][] |
| [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][] | |

[build-badge]: https://github.com/testing-library/eslint-plugin-testing-library/actions/workflows/pipeline.yml/badge.svg
[build-url]: https://github.com/testing-library/eslint-plugin-testing-library/actions/workflows/pipeline.yml
2 changes: 1 addition & 1 deletion docs/rules/await-async-query.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce promises from async queries to be handled (await-async-query)
# Enforce promises from async queries to be handled (`testing-library/await-async-query`)

Ensure that promises returned by async queries are handled properly.

2 changes: 1 addition & 1 deletion docs/rules/await-async-utils.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce promises from async utils to be handled (await-async-utils)
# Enforce promises from async utils to be handled (`testing-library/await-async-utils`)

Ensure that promises returned by async utils are handled properly.

2 changes: 1 addition & 1 deletion docs/rules/await-fire-event.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce promises from fire event methods to be handled (await-fire-event)
# Enforce promises from fire event methods to be handled (`testing-library/await-fire-event`)

Ensure that promises returned by `fireEvent` methods are handled
properly.
2 changes: 1 addition & 1 deletion docs/rules/consistent-data-testid.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforces consistent naming for the data-testid attribute (consistent-data-testid)
# Enforces consistent naming for the data-testid attribute (`testing-library/consistent-data-testid`)

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

2 changes: 1 addition & 1 deletion docs/rules/no-await-sync-events.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow unnecessary `await` for sync events (no-await-sync-events)
# Disallow unnecessary `await` for sync events (`testing-library/no-await-sync-events`)

Ensure that sync simulated events are not awaited unnecessarily.

2 changes: 1 addition & 1 deletion docs/rules/no-await-sync-query.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow unnecessary `await` for sync queries (no-await-sync-query)
# Disallow unnecessary `await` for sync queries (`testing-library/no-await-sync-query`)

Ensure that sync queries are not awaited unnecessarily.

2 changes: 1 addition & 1 deletion docs/rules/no-container.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow the use of `container` methods (no-container)
# Disallow the use of `container` methods (`testing-library/no-container`)

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.

2 changes: 1 addition & 1 deletion docs/rules/no-debug.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow the use of `debug` (no-debug)
# Disallow the use of `debug` (`testing-library/no-debug`)

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.

10 changes: 5 additions & 5 deletions docs/rules/no-dom-import.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow importing from DOM Testing Library
# Disallow importing from DOM Testing Library (`testing-library/no-dom-import`)

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

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

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

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

Examples of **incorrect** code for this rule:
2 changes: 1 addition & 1 deletion docs/rules/no-manual-cleanup.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow the use of `cleanup` (no-manual-cleanup)
# Disallow the use of `cleanup` (`testing-library/no-manual-cleanup`)

`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.

2 changes: 1 addition & 1 deletion docs/rules/no-node-access.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow direct Node access (no-node-access)
# Disallow direct Node access (`testing-library/no-node-access`)

The Testing Library already provides methods for querying DOM elements.

2 changes: 1 addition & 1 deletion docs/rules/no-promise-in-fire-event.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow the use of promises passed to a `fireEvent` method (no-promise-in-fire-event)
# Disallow the use of promises passed to a `fireEvent` method (`testing-library/no-promise-in-fire-event`)

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

2 changes: 1 addition & 1 deletion docs/rules/no-render-in-setup.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow the use of `render` in setup functions (no-render-in-setup)
# Disallow the use of `render` in setup functions (`testing-library/no-render-in-setup`)

## Rule Details

2 changes: 1 addition & 1 deletion docs/rules/no-wait-for-empty-callback.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Empty callbacks inside `waitFor` and `waitForElementToBeRemoved` are not preferred (no-wait-for-empty-callback)
# Empty callbacks inside `waitFor` and `waitForElementToBeRemoved` are not preferred (`testing-library/no-wait-for-empty-callback`)

## Rule Details

2 changes: 1 addition & 1 deletion docs/rules/no-wait-for-multiple-assertions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Multiple assertions inside `waitFor` are not preferred (no-wait-for-multiple-assertions)
# Disallow the use of multiple expect inside `waitFor` (`testing-library/no-wait-for-multiple-assertions`)

## Rule Details

2 changes: 1 addition & 1 deletion docs/rules/no-wait-for-side-effects.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Side effects inside `waitFor` are not preferred (no-wait-for-side-effects)
# Disallow the use of side effects inside `waitFor` (`testing-library/no-wait-for-side-effects`)

## Rule Details

6 changes: 3 additions & 3 deletions docs/rules/no-wait-for-snapshot.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Ensures no snapshot is generated inside of a `wait` call' (no-wait-for-snapshot)
# Ensures no snapshot is generated inside a `waitFor` call (`testing-library/no-wait-for-snapshot`)

Ensure that no calls to `toMatchSnapshot` or `toMatchInlineSnapshot` are made from within a `waitFor` method (or any of the other async utility methods).

## Rule Details

The `waitFor()` method runs in a timer loop. So it'll retry every n amount of time.
If a snapshot is generated inside the wait condition, jest will generate one snapshot per loop.
If a snapshot is generated inside the wait condition, jest will generate one snapshot per each loop.

The problem then is the amount of loop ran until the condition is met will vary between different computers (or CI machines). This leads to tests that will regenerate a lot of snapshots until the condition is matched when devs run those tests locally updating the snapshots; e.g devs cannot run `jest -u` locally or it'll generate a lot of invalid snapshots who'll fail during CI.
The problem then is the amount of loop ran until the condition is met will vary between different computers (or CI machines). This leads to tests that will regenerate a lot of snapshots until the condition is matched when devs run those tests locally updating the snapshots; e.g. devs cannot run `jest -u` locally, or it'll generate a lot of invalid snapshots which will fail during CI.

Note that this lint rule prevents from generating a snapshot from within any of the [async utility methods](https://testing-library.com/docs/dom-testing-library/api-async).

2 changes: 1 addition & 1 deletion docs/rules/prefer-explicit-assert.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using explicit assertions rather than just `getBy*` queries (prefer-explicit-assert)
# Suggest using explicit assertions rather than just `getBy*` queries (`testing-library/prefer-explicit-assert`)

Testing Library `getBy*` queries throw an error if the element is not
found. Some users like this behavior to use the query itself as an
6 changes: 3 additions & 3 deletions docs/rules/prefer-find-by.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Suggest using `findBy*` methods instead of the `waitFor` + `getBy` queries (prefer-find-by)
# Suggest using `findBy*` methods instead of the `waitFor` + `getBy` queries (`testing-library/prefer-find-by`)

findBy* queries are a simple combination of getBy* queries and waitFor. The findBy\* queries accept the waitFor options as the last argument. (i.e. screen.findByText('text', queryOptions, waitForOptions))

## Rule details

This rule aims to use `findBy*` or `findAllBy*` queries to wait for elements, rather than using `waitFor`, or the deprecated methods `waitForElement` and `wait`.
This rules analyzes those cases where `waitFor` is used with just one query method, in the form of an arrow function with only one statement (that is, without a block of statements). Given the callback could be more complex, this rule does not consider function callbacks or arrow functions with blocks of code
This rule aims to use `findBy*` or `findAllBy*` queries to wait for elements, rather than using `waitFor`, or the deprecated methods `waitForElement` and `wait`.
This rule analyzes those cases where `waitFor` is used with just one query method, in the form of an arrow function with only one statement (that is, without a block of statements). Given the callback could be more complex, this rule does not consider function callbacks or arrow functions with blocks of code

Examples of **incorrect** code for this rule

2 changes: 1 addition & 1 deletion docs/rules/prefer-presence-queries.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce specific queries when checking element is present or not (prefer-presence-queries)
# Enforce specific queries when checking element is present or not (`testing-library/prefer-presence-queries`)

The (DOM) Testing Library allows to query DOM elements using different types of queries such as `get*` and `query*`. Using `get*` throws an error in case the element is not found, while `query*` returns null instead of throwing (or empty array for `queryAllBy*` ones). These differences are useful in some situations:

2 changes: 1 addition & 1 deletion docs/rules/prefer-screen-queries.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using screen while using queries (prefer-screen-queries)
# Suggest using `screen` while using queries (`testing-library/prefer-screen-queries`)

## Rule Details

6 changes: 3 additions & 3 deletions docs/rules/prefer-user-event.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Use [userEvent](https://github.com/testing-library/user-event) over using `fireEvent` for user interactions (prefer-user-event)
# Suggest using `userEvent` library instead of `fireEvent` for simulating user interaction (`testing-library/prefer-user-event`)

From
[testing-library/dom-testing-library#107](https://github.com/testing-library/dom-testing-library/issues/107):
@@ -97,8 +97,8 @@ When you don't want to use `userEvent`, such as if a legacy codebase is still us

## Further Reading

- [userEvent repository](https://github.com/testing-library/user-event)
- [userEvent in the react-testing-library docs](https://testing-library.com/docs/ecosystem-user-event)
- [`user-event` repository](https://github.com/testing-library/user-event)
- [`userEvent` in the Testing Library docs](https://testing-library.com/docs/ecosystem-user-event)

## Appendix

2 changes: 1 addition & 1 deletion docs/rules/prefer-wait-for.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Use `waitFor` instead of deprecated wait methods (prefer-wait-for)
# Use `waitFor` instead of deprecated wait methods (`testing-library/prefer-wait-for`)

`dom-testing-library` v7 released a new async util called `waitFor` which satisfies the use cases of `wait`, `waitForElement`, and `waitForDomChange` making them deprecated.

2 changes: 1 addition & 1 deletion docs/rules/render-result-naming-convention.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce a valid naming for return value from `render` (render-result-naming-convention)
# Enforce a valid naming for return value from `render` (`testing-library/render-result-naming-convention`)

> The name `wrapper` is old cruft from `enzyme` and we don't need that here. The return value from `render` is not "wrapping" anything. It's simply a collection of utilities that you should actually not often need anyway.
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -11,9 +11,8 @@ module.exports = {
lines: 100,
statements: 100,
},
// TODO drop this custom threshold after v4
'./lib/node-utils.ts': {
branches: 85,
branches: 90,
functions: 90,
lines: 90,
statements: 90,
17 changes: 0 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -20,23 +20,6 @@
"bugs": {
"url": "https://github.com/testing-library/eslint-plugin-testing-library/issues"
},
"release": {
"pkgRoot": "dist",
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
]
},
"main": "index.js",
"scripts": {
"build": "tsc",