question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New rule: prefer-user-event

See original GitHub issue

When 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 think hover, 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:24 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
nickmccurdycommented, Jun 16, 2020

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 the user-event package.

2reactions
nickmccurdycommented, Jun 18, 2020

Do we have clear then about what we want to include in this rule?

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 the user-event event vs just allowing both (most ESLint rules seem to use string literals for this).

If so, I’d include it in v4 as optional. If we have everything but this ready for v4 I’d release it and then include this in a potential v4.1. Sounds good?

👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found