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.type with empty string causes a warning about an unhandled promise rejection #633
Comments
Thanks for this report. Regarding the empty string: What's the purpose of using |
🎉 This issue has been resolved in version 13.1.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
The UnhandledPromiseRejectionWarning is fixed. You should get a console error now. I closed this issue for now. |
@all-contributors add @InExtremaRes bug |
I've put up a pull request to add @InExtremaRes! 🎉 |
@ph-fritsche I caught this error in a suite that tested input validation. There was a set of strings to be used as inputs and the expected messages the use would see, something like this: [
['abc', 'Too short'],
['&ab', 'No symbols allowed'],
['', 'Required'], // <-----------
// ... an so on...
] The input field is required so clicking it and leave it empty should mark it as such. I understand this can be accomplish but other means, like However I don't see why passing an empty string is an error. As I said I expected such behaviour to be equivalent to click the input and then do nothing. Besides, the error is very cryptic, I thought "what key descriptor are you talking about?", I didn't realize until I saw your PR. Is that error really expected even if I never used |
The error is meant for every input that can not be converted to a key definition. Which is the case for an empty string. I'm not sure yet if it would be a good idea to skip the implementation right away if the string is empty. |
I agree that my case is a not very compelling reason to allow an empty string, but maybe the message can be improved. It took me a while to realize where the error came from. |
For what it's worth we had the exact same set up and issue as @InExtremaRes, so maybe it isn't that unusual? |
I can back this up. We had this issue and it took some time to find out why and where the error is reported. A better error message would help A LOT. |
@zaicevas @InExtremaRes Please have a look at #666 |
🎉 This issue has been resolved in version 13.1.6 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
How did you solve validating your input field for falsey values like an empty string? You mentioned something about |
He initially expected |
FYI, I had the same problem. Thanks for the info. In my case, I had a helper function that passed the text as a variable to the I solved this by modifying my code to type a TAB character if the given string was empty. And that worked great because it removed focus from the element (and then triggered the "required" error message on my form.) |
Here's what I did: import { fireEvent } from '@testing-library/react';
const setInputToBlank = (input) => fireEvent.input(input, { target: { value: '' } });
// Then call in your test like this:
const emailInput = screen.getByLabelText(/email address/i);
await setInputToBlank(emailInput); |
@testing-library/user-event
version: 13.0.16Relevant code or config
What you did:
I used
userEvent.type
with an empty string.What happened:
Running the tests with jest (
npm test
, is a CRA project) causes node.js to emit this warning:Tested with node.js 12.21.0 and 14.16.0.
The warning seems to be an unhandled rejected promise, so an actual error was thrown.
The warning was not emitted using user-event 12 (the default that came with CRA).
The text was updated successfully, but these errors were encountered: