Checking if input value is empty string using toHaveValue
romulof opened this issue · comments
@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:
expect(inputElement).toHaveValue('');
What you did:
I wanted to check if an input value is empty.
What happened:
Jest fails assertion saying that expeted ''
but received null
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:
expect(inputElement.value).toBe('');
Suggested solution:
Either revert this internal conversion, or also toHaveValue
parameter if it is an empty string.