-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,637 additions
and
3,751 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Guide: migrating to v6 | ||
|
||
If you are not on v5 yet, we recommend first following the [v5 migration guide](docs/migration-guides/v5.md). | ||
|
||
## Overview | ||
|
||
- `prefer-wait-for` was removed | ||
- `no-wait-for-empty-callback` was removed | ||
- `await-fire-event` is now called `await-async-events` with support for an `eventModule` option with `userEvent` and/or `fireEvent` | ||
- `await-async-events` is now enabled by default for `fireEvent` in Vue and Marko shared configs | ||
- `await-async-events` is now enabled by default for `userEvent` in all shared configs | ||
- `await-async-query` is now called `await-async-queries` | ||
- `no-await-async-query` is now called `no-await-async-queries` | ||
- `no-render-in-setup` is now called `no-render-in-lifecycle` | ||
- `no-await-sync-events` is now enabled by default in React, Angular, and DOM shared configs | ||
- `no-manual-cleanup` is now enabled by default in React and Vue shared configs | ||
- `no-global-regexp-flag-in-query` is now enabled by default in all shared configs | ||
- `no-node-access` is now enabled by default in DOM shared config | ||
- `no-debugging-utils` now reports all debugging utility methods by default | ||
- `no-debugging-utils` now defaults to `warn` instead of `error` in all shared configs | ||
|
||
## Steps to upgrade | ||
|
||
- Removing `testing-library/prefer-wait-for` if you were referencing it manually somewhere | ||
- Removing `testing-library/no-wait-for-empty-callback` if you were referencing it manually somewhere | ||
- Renaming `testing-library/await-fire-event` to `testing-library/await-async-events` if you were referencing it manually somewhere | ||
- Renaming `testing-library/await-async-query` to `testing-library/await-async-queries` if you were referencing it manually somewhere | ||
- Renaming `testing-library/no-await-async-query` to `testing-library/no-await-async-queries` if you were referencing it manually somewhere | ||
- Renaming `testing-library/no-render-in-setup` to `testing-library/no-render-in-lifecycle` if you were referencing it manually somewhere | ||
- Being aware of new rules enabled or changed above in shared configs which can lead to newly reported errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# Enforce promises from async event methods are handled (`testing-library/await-async-events`) | ||
|
||
💼 This rule is enabled in the following configs: `angular`, `dom`, `marko`, `react`, `vue`. | ||
|
||
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
Ensure that promises returned by `userEvent` (v14+) async methods or `fireEvent` (only Vue and Marko) async methods are handled properly. | ||
|
||
## Rule Details | ||
|
||
This rule aims to prevent users from forgetting to handle promise returned from async event | ||
methods. | ||
|
||
> ⚠️ `fireEvent` methods are async only on following Testing Library packages: | ||
> | ||
> - `@testing-library/vue` (supported by this plugin) | ||
> - `@testing-library/svelte` (not supported yet by this plugin) | ||
> - `@marko/testing-library` (supported by this plugin) | ||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
fireEvent.click(getByText('Click me')); | ||
|
||
fireEvent.focus(getByLabelText('username')); | ||
fireEvent.blur(getByLabelText('username')); | ||
|
||
// wrap a fireEvent method within a function... | ||
function triggerEvent() { | ||
return fireEvent.click(button); | ||
} | ||
triggerEvent(); // ...but not handling promise from it is incorrect too | ||
``` | ||
|
||
```js | ||
userEvent.click(getByText('Click me')); | ||
userEvent.tripleClick(getByText('Click me')); | ||
userEvent.keyboard('foo'); | ||
|
||
// wrap a userEvent method within a function... | ||
function triggerEvent() { | ||
return userEvent.click(button); | ||
} | ||
triggerEvent(); // ...but not handling promise from it is incorrect too | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
// `await` operator is correct | ||
await fireEvent.focus(getByLabelText('username')); | ||
await fireEvent.blur(getByLabelText('username')); | ||
|
||
// `then` method is correct | ||
fireEvent.click(getByText('Click me')).then(() => { | ||
// ... | ||
}); | ||
|
||
// return the promise within a function is correct too! | ||
const clickMeArrowFn = () => fireEvent.click(getByText('Click me')); | ||
|
||
// wrap a fireEvent method within a function... | ||
function triggerEvent() { | ||
return fireEvent.click(button); | ||
} | ||
await triggerEvent(); // ...and handling promise from it is correct also | ||
|
||
// using `Promise.all` or `Promise.allSettled` with an array of promises is valid | ||
await Promise.all([ | ||
fireEvent.focus(getByLabelText('username')), | ||
fireEvent.blur(getByLabelText('username')), | ||
]); | ||
``` | ||
|
||
```js | ||
// `await` operator is correct | ||
await userEvent.click(getByText('Click me')); | ||
await userEvent.tripleClick(getByText('Click me')); | ||
|
||
// `then` method is correct | ||
userEvent.keyboard('foo').then(() => { | ||
// ... | ||
}); | ||
|
||
// return the promise within a function is correct too! | ||
const clickMeArrowFn = () => userEvent.click(getByText('Click me')); | ||
|
||
// wrap a userEvent method within a function... | ||
function triggerEvent() { | ||
return userEvent.click(button); | ||
} | ||
await triggerEvent(); // ...and handling promise from it is correct also | ||
|
||
// using `Promise.all` or `Promise.allSettled` with an array of promises is valid | ||
await Promise.all([ | ||
userEvent.click(getByText('Click me')); | ||
userEvent.tripleClick(getByText('Click me')); | ||
]); | ||
``` | ||
|
||
## Options | ||
|
||
- `eventModule`: `string` or `string[]`. Which event module should be linted for async event methods. Defaults to `userEvent` which should be used after v14. `fireEvent` should only be used with frameworks that have async fire event methods. | ||
|
||
## Example | ||
|
||
```json | ||
{ | ||
"testing-library/await-async-events": [ | ||
2, | ||
{ | ||
"eventModule": "userEvent" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"testing-library/await-async-events": [ | ||
2, | ||
{ | ||
"eventModule": "fireEvent" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"testing-library/await-async-events": [ | ||
2, | ||
{ | ||
"eventModule": ["fireEvent", "userEvent"] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
- `userEvent` is below v14, before all event methods are async | ||
- `fireEvent` methods are sync for most Testing Library packages. If you are not using Testing Library package with async events, you shouldn't use this rule. | ||
|
||
## Further Reading | ||
|
||
- [Vue Testing Library fireEvent](https://testing-library.com/docs/vue-testing-library/api#fireevent) |
2 changes: 1 addition & 1 deletion
2
docs/rules/await-async-query.md → docs/rules/await-async-queries.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/rules/no-await-sync-query.md → docs/rules/no-await-sync-queries.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.