Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

userEvent.clear() does not work for input types w/o setSelectionRange support #282

Closed
9still opened this issue May 16, 2020 · 2 comments
Closed

Comments

@9still
Copy link
Contributor

9still commented May 16, 2020

userEvent.clear() uses setSelectionRange to clear the input, but setSelectionRange is only supported by a subset of input elements

Per https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange

Note that accordingly to the WHATWG forms spec selectionStart, selectionEnd properties and setSelectionRange method apply only to inputs of types text, search, URL, tel and password. Chrome, starting from version 33, throws an exception while accessing those properties and method on the rest of input types. For example, on input of type number: "Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection".

This implies that userEvent.clear() is not actually supported for email and number input types, amongst others.

To make matters worse, jsdom (tested on 16.2.2) throws a cryptic exception (InvalidStateError: The object is in an invalid state.) when you try to use .clear() on an unsupported input element, and jest does not print out a call stack, making the problem a bit more painful to find.

@kentcdodds
Copy link
Member

This was recently fixed via a workaround: #262

Please update to the latest version. Thanks!

@9still
Copy link
Contributor Author

9still commented May 17, 2020

Awesome, the new version works great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants