fireEvent.focus should be discouraged
See original GitHub issueDescribe the feature you’d like:
Discourage fireEvent.focus(element)
Suggested implementation:
Prefer element.focus()
Describe alternatives you’ve considered:
Don’t use existing API or call element.focus()
internally.
Teachability, Documentation, Adoption, Migration Strategy:
fireEvent.focus(element)
will not move the focus to the element i.e. document.activeElement !== element
. element.focus()
will result in document.activeElement === element
and dispatch the focus event. fireEvent.focus
will also work on non-interactive elements whereas element.focus
does not.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:14 (14 by maintainers)
Top Results From Across the Web
Considerations for fireEvent | Testing Library
If an element is focused, a focus event is dispatched, the active element in the document changes, and the previously focused element is...
Read more >How to test which input has the focus when tab button is pressed
I have two inputs. When input1(with autocomplete functionality) is in focus, clicking the Tab button should either auto fill input1 with a text ......
Read more >How to use the @testing-library/dom.fireEvent.focus function ...
To help you get started, we've selected a few @testing-library/dom.fireEvent.focus examples, based on popular ways it is used in public projects.
Read more >Improving React Testing Library tests | Alex Khomenko
Focus on testing from the user's point of view and avoidance of ... Properly written tests can not only help to prevent regressions...
Read more >Testing User Interfaces For Beginners - Joy of Code
You can use tests to prevent people from submitting code in a pull request ... I'm going to focus on testing and giving...
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 FreeTop 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
Top GitHub Comments
How would it look like? user-event tries to mimic what a user does. AFAIK users can’t give focus to an element. They have to click on it or use tab
That’s a fair point. Maybe @eps1lon’s original suggestion is the best we can do. Recommend that people use
.focus()
on the dom node rather thanfireEvent.focus
.