-
Notifications
You must be signed in to change notification settings - Fork 409
typescript declaration for ToHaveValue doesn't allow null #240
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
Comments
Yes, I agree. Though the type definitions are not in this repo, but in DefinitelyTyped. Not sure what the process is there, if we also open an issue there, or just the PR (if you're up for it that's cool BTW). But I'm fine to keep this issue here to keep track of this, because ultimately is an issue with our lib, even if we do not provide the types right here (I wish we did). |
OK thanks. I'm new to contributing but since it looks like you've agreed it's a fault, and it should be simple to fix, it looks like a good one to cut my teeth on. I'll try a PR on DefinitelyTyped and reference this issue. |
I see the fix has been released in https://www.npmjs.com/package/@types/testing-library__jest-dom/v/5.0.4. As far as I'm concerned, you can close this issue now |
@testing-library/jest-dom
version: 5.5.0node
version: 12.16.2npm
(oryarn
) version: 6.14.4react-testing-library
version: (if applicable) 10.0.4Relevant code or config:
==> typescript warning
What you did:
I'm using <
input type="number"
> to prompt for an optional numeric value. It seems the obvious way to handle an empty value is to use null , and certainly React doesn't give any warnings when you try to do this.What happened:
Typescript gives a warning because the method signature for toHaveValue doesn't allow null. using the non-null assertion operator (i.e.
expect(inputElement).toHaveValue(null!);
works fine and is the best workaround IMO.It might be possible to set an empty string to indicate an empty value, but this would require me to declare my state variable as
number | string | null
which is definitely not desirableSuggested solution:
From what I can tell there are already some tests calling it with null (just google toHaveValue null and they come up at the top of the list), so I presume it is valid to do this and you just need to update the typescript declarations.
The text was updated successfully, but these errors were encountered: