We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
@testing-library/jest-dom
node
jest
vitest
npm
yarn
expect(inputElement).toHaveValue('');
I wanted to check if an input value is empty.
Jest fails assertion saying that expeted '' but received null
''
null
Just create an input with empty value.
jest-dom internally converts empty string to null which is confusing, because when I write the code bellow it works:
expect(inputElement.value).toBe('');
Either revert this internal conversion, or also toHaveValue parameter if it is an empty string.
toHaveValue
The text was updated successfully, but these errors were encountered:
One workaround is to replace .toHaveValue("") with .toBeEmpty()
.toHaveValue("")
.toBeEmpty()
Sorry, something went wrong.
toBeEmpty() is deprecated. This is the right way:
toBeEmpty()
expect(inputElement).not.toHaveValue()
No branches or pull requests
@testing-library/jest-dom
version: 5.14.1node
version: 18.18.2jest
(orvitest
) version: 29.7.0npm
(oryarn
) version: 1.22.19 (yarn)Relevant code or config:
What you did:
I wanted to check if an input value is empty.
What happened:
Jest fails assertion saying that expeted
''
but receivednull
Reproduction:
Just create an input with empty value.
Problem description:
jest-dom internally converts empty string to
null
which is confusing, because when I write the code bellow it works:Suggested solution:
Either revert this internal conversion, or also
toHaveValue
parameter if it is an empty string.The text was updated successfully, but these errors were encountered: