New rule: prefer-user-event
See original GitHub issueWhen https://github.com/testing-library/dom-testing-library/pull/616 gets merged, userEvent
will be part of DOM testing library.
We could create rules for events on userEvent
that are preferred over their fireEvent
counterparts.
Before we start implementing rules, there are some thing we need to clarify first:
-
Kent already mentioned
click
would be a good candidate, are there any others that could benefit from this rule? I thinkhover
,unhover
could also be included in within this rule. -
Should it be one rule for all events, or a rule per event? The latter would allow us to disable/enable specific events… but we could also create a config for it…
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:24 (14 by maintainers)
Top Results From Across the Web
eslint-plugin-testing-library/prefer-user-event.md at main
Rule Details This rule enforces the usage of userEvent methods over fireEvent . By default, the methods from userEvent take precedence, but you...
Read more >user-event v13 - Testing Library
user -event is a companion library for Testing Library that provides more advanced simulation of browser interactions than the built-in fireEvent ...
Read more >React Testing Library best practices | Ben Ilegbodu
The prefer-user-event ESLint rule enforces the usage of userEvent over fireEvent , so this is now an error. We should've known we weren't ......
Read more >React-testing-library: fireEvent vs userEvent - mimacom blog
The answer to this question is easy: we should always try to use userEvent over fireEvent whenever we are able to, except in...
Read more >chrome.events - Chrome Developers
To add rules call the addRules() function of the event object. It takes an array of rule instances as its first parameter and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The merge into
dom-testing-library
has been cancelled, but it would still be nice to have this rule to inform users about when they should be using theuser-event
package.I thought we agreed on adding one new rule that would check all events that should be used with
user-event
by default, with a config to toggle them individually. That being said, I’m not sure if we’d want to have distinct options for banning theuser-event
event vs just allowing both (most ESLint rules seem to use string literals for this).👍