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.

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
GreenGremlincommented, Apr 16, 2021

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.

0reactions
github-actions[bot]commented, Apr 19, 2021

🎉 This issue has been resolved in version 13.1.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

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

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