User event element types are more narrow than what is returned by RTS queries
See original GitHub issue@testing-library/user-event
version:13.1.1
- Testing Framework and version: Jest v26.6.3
- DOM Environment: jsdom v16.5.0
Relevant code or config
userEvent.paste(screen.getByRole('textbox'), 'Ralph');
// or
userEvent.upload(screen.getByLabelText('labelText'), file);
What you did:
Compiled using TypeScript.
What happened:
Type error
Argument of type 'HTMLElement' is not assignable to parameter of type 'HTMLInputElement | HTMLTextAreaElement'.
Type 'HTMLElement' is missing the following properties from type 'HTMLTextAreaElement': autocomplete, cols, defaultValue, dirName, and 26 more.ts(2345)
Reproduction repository:
N/A
Problem description:
Elements returned by react-testing-library queries are of type HTMLElement
but user-event functions take more narrow element types like HTMLInputElement | HTMLLabelElement
. It looks like the type change was made in @testing-library/user-event v13.
Suggested solution:
The type definitions for userEvent.paste
and userEvent.upload
should either be relaxed to allow HTMLElement
or query methods should be added that return the more narrow element types. Type casting should not be required.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
user-event - Bountysource
Simulate user events for react-testing-library. Become a Bounty Hunter ... User event element types are more narrow than what is returned by RTS...
Read more >userEvent.type's delay hangs forever · Issue #565 - GitHub
My jest test simulates the user clicking an input, and clearing it's existing text: await userEvent.type(inputElem, '{selectall}{backspace}' ...
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 ...
Read more >Simulate Clicks in a Test with the User Event Library
The interface is fairly straight forward in most cases you simply say userEvent["eventName"] and then pass in an element returned from a findBy...
Read more >Using the Data API for Aurora Serverless v1
The API provides a more secure way to use AWS Lambda. It enables you to access your DB cluster without your needing to...
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
Type casting is not ideal, since it guarantees nothing. A better solution would be to have a way to filter query results by tag name, which would guarantee the query is returning the expected type. In the meantime, it feels broken for user-event functions to be incompatible with react-testing-library queries, if they can’t be used without type casting.
🎉 This issue has been resolved in version 13.1.5 🎉
The release is available on:
npm package (@latest dist-tag)
Your semantic-release bot 📦🚀