testing-library / jest-dom

:owl: Custom jest matchers to test the state of the DOM

Home Page:https://testing-library.com/docs/ecosystem-jest-dom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Checking if input value is empty string using toHaveValue

romulof opened this issue · comments

  • @testing-library/jest-dom version: 5.14.1
  • node version: 18.18.2
  • jest (or vitest) version: 29.7.0
  • npm (or yarn) 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.