question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Leading numbers trimmed when using type for decimals in numeric input

See original GitHub issue
  • @testing-library/user-event version: 12.0.2
  • Testing Framework and version: jest 26.0.1
  • DOM Environment: jsdom 16.2.2

What you did: Testing floating point values entered asynchronously into numeric text using type. I had mentioned this at the end of #336, and finally got around to testing it today. I’ve updated the sandbox dependencies. I’ve also updated the tests to reflect the new API changes.

What happened: The leading numbers (before decimal point) are getting trimmed off in my tests.

Reproduction sandbox: https://codesandbox.io/s/user-event-decimals-trimmed-hf0wx

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, Jun 21, 2020

You’re getting issues because 3. is an invalid value in a number input so you can’t programmatically set that value. This is why we have the complex logic we do in the type utility.

Also, the value is set programmatically in the fireEvent utility in DOM Testing Library. Which is why you can’t do it by dispatching an event. I suggest diving into the code a bit. I’m on my phone, but you should be able to find it.

1reaction
kentcdoddscommented, Jun 17, 2020

Please do! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle floats and decimal separators with html5 input ...
Input type =number · User enters "4,55" to input field · $("#my_input").val(); returns "4,55" · Thats fine, I can replace comma with dot...
Read more >
How to: Pad a Number with Leading Zeros | Microsoft Learn
To pad an integer with leading zeros to a specific length ... Determine whether you want to display the integer as a decimal...
Read more >
decimal — Decimal fixed point and floating point arithmetic ...
Decimal floating point objects share many properties with the other built-in numeric types such as float and int . All of the usual...
Read more >
LEADINGZEROS( ) function - HighBond
Leading and trailing spaces are automatically trimmed from character values, and from the result of character expressions, before the leading zeros are added....
Read more >
Article: Number Formatting - Boomi Community
Numbers after the decimal will be truncated unless it is explicitly defined but numbers before the decimal will be preserved whether you defined ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found