Skip to content
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

.toHaveValue expect string values for input type range #364

Open
Okazari opened this issue May 10, 2021 · 2 comments · May be fixed by #365
Open

.toHaveValue expect string values for input type range #364

Okazari opened this issue May 10, 2021 · 2 comments · May be fixed by #365

Comments

@Okazari
Copy link

Okazari commented May 10, 2021

  • @testing-library/jest-dom version: 5.11.9
  • node version: 12.16.0
  • npm (or yarn) version: 1.22.5

Relevant code or config:

const MyComponent = () => <input data-test="input" type="range" value={5} onChange={() => {}} />

  it('should work', () => {
    render(<MyComponent />);
    let inputRange = screen.getByTestId('input');
    expect(inputRange).toHaveValue(5);
  });

Hey there ! I just stumble upon a strange case were testing value for a input type range expect values to be string.
I find it quite odd since those input value are always numbers.

Reproduction:

Here is a minimap repro in a codesandbox https://codesandbox.io/s/react-testing-library-demo-forked-pve4d?file=/src/__tests__/hello.js

Problem description:

  • .toHaveValue expect string values for input type range

It force the test to use strings instead of number. It is annoying when dealing with const that are numbers.

Suggested solution:

  • .toHaveValue could expect number values for input type range
@Okazari
Copy link
Author

Okazari commented May 10, 2021

I may open a PR for that if you can point me where the job is done for input type="number" 👍

@gnapse
Copy link
Member

gnapse commented May 11, 2021

Thanks for your bug report. Indeed, this should work the same as with <input type="number" />. Here's where we treat numeric inputs differently:

jest-dom/src/utils.js

Lines 191 to 192 in 637529e

case 'number':
return inputElement.value === '' ? null : Number(inputElement.value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants