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

Leading numbers trimmed when using type for decimals in numeric input #360

Closed
tadger opened this issue Jun 16, 2020 · 9 comments
Closed
Assignees
Labels
bug Something isn't working released

Comments

@tadger
Copy link

tadger commented Jun 16, 2020

  • @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

@nickmccurdy
Copy link
Member

Could this be related to #346?

@nickmccurdy nickmccurdy added the needs investigation Someone has to do research on this label Jun 17, 2020
@lourenci
Copy link
Collaborator

Can I try this one?

@kentcdodds
Copy link
Member

Please do! :)

@nickmccurdy nickmccurdy added the bug Something isn't working label Jun 18, 2020
@lourenci
Copy link
Collaborator

lourenci commented Jun 18, 2020

I don't know why (yet) but sending an input event with a point in the end will empty the input value. E.g.:

  fireEvent.input(input, {
    target: { value: '3' },
    data: '3',
    inputType: 'insertText'
  })
  console.log(input.value) // "3"

  fireEvent.input(input, {
    target: { value: '3.' },
    data: '.',
    inputType: 'insertText'
  })
  console.log(input.value) // ""

So any value I got before "typing" the point turn empty when I "type" the ".".

I don't know yet whether this is a user-event, a jsdom, or a fireEvent bug. What do you guys think about that?

I think it's easy to solve here once we settle on an userEvent bug.

@nickmccurdy
Copy link
Member

nickmccurdy commented Jun 19, 2020

Can that be replicated using raw DOM events in JSDOM?

@lourenci
Copy link
Collaborator

I can't replicate even a common change in my browser. 😞 I don't know why, but this snippet does not change the input value:

inputElement.dispatchEvent(new InputEvent('input', {
  bubbles: true, cancelable: false, composed: true, data: '1', inputType: 'insertText'
}))

Maybe, just trusted input events can change the input's value?

@kentcdodds
Copy link
Member

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.

@lourenci
Copy link
Collaborator

I'll handle that on the type utility so. Thank you guys for the helper.

@kentcdodds
Copy link
Member

🎉 This issue has been resolved in version 12.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickmccurdy nickmccurdy removed the needs investigation Someone has to do research on this label Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

4 participants