Skip to content
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

feat(prefer-user-event): add support for React Native events #958

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions docs/rules/prefer-user-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ The following table lists all the possible equivalents from the low-level API `f
| ---------------- | ----------------------------------------------------------------------------------------------------------- |
| `click` | <ul><li>`click`</li><li>`type`</li><li>`selectOptions`</li><li>`deselectOptions`</li></ul> |
| `change` | <ul><li>`upload`</li><li>`type`</li><li>`clear`</li><li>`selectOptions`</li><li>`deselectOptions`</li></ul> |
| `changeText` | <ul><li>`type`</li></ul> |
| `dblClick` | <ul><li>`dblClick`</li></ul> |
| `input` | <ul><li>`type`</li><li>`upload`</li><li>`selectOptions`</li><li>`deselectOptions`</li><li>`paste`</li></ul> |
| `keyDown` | <ul><li>`type`</li><li>`tab`</li></ul> |
Expand All @@ -138,3 +139,5 @@ The following table lists all the possible equivalents from the low-level API `f
| `pointerOut` | <ul><li>`unhover`</li></ul> |
| `pointerOver` | <ul><li>`hover`</li><li>`selectOptions`</li><li>`deselectOptions`</li></ul> |
| `pointerUp` | <ul><li>`click`</li><li>`dblClick`</li><li>`selectOptions`</li><li>`deselectOptions`</li></ul> |
| `press` | <ul><li>`press`</li></ul> |
| `scroll` | <ul><li>`scrollTo`</li></ul> |
5 changes: 5 additions & 0 deletions lib/rules/prefer-user-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ export const UserEventMethods = [
'hover',
'unhover',
'paste',
'press',
'scrollTo',
] as const;
type UserEventMethodsType = (typeof UserEventMethods)[number];

// maps fireEvent methods to userEvent. Those not found here, do not have an equivalent (yet)
export const MAPPING_TO_USER_EVENT: Record<string, UserEventMethodsType[]> = {
click: ['click', 'type', 'selectOptions', 'deselectOptions'],
change: ['upload', 'type', 'clear', 'selectOptions', 'deselectOptions'],
changeText: ['type'],
dblClick: ['dblClick'],
input: ['type', 'upload', 'selectOptions', 'deselectOptions', 'paste'],
keyDown: ['type', 'tab'],
Expand All @@ -51,6 +54,8 @@ export const MAPPING_TO_USER_EVENT: Record<string, UserEventMethodsType[]> = {
pointerOut: ['unhover'],
pointerOver: ['hover', 'selectOptions', 'deselectOptions'],
pointerUp: ['click', 'dblClick', 'selectOptions', 'deselectOptions'],
press: ['press'],
scroll: ['scrollTo'],
};

function buildErrorMessage(fireEventMethod: string) {
Expand Down
Loading