GoncharukBro / react-input

98 stars 7 forks source link

react-testing not works with @react-input/mask #21

Closed Tsugami closed 5 months ago

Tsugami commented 5 months ago

Reproduction example

https://github.com/Tsugami/react-input-with-testing/blob/master/src/form/cpnj-cpf-input.spec.tsx#L20

Expected

I expected the test to pass and the input being updated with mask

Output

Expected the element to have value:
  785.563.840-72
Received:
  __.___.___/____-__
GoncharukBro commented 5 months ago

You use the showMask parameter, which actually inserts a value into the input element, and since value input in testing tools starts at the end of the value, the initial cursor position in the input will be equal to the length of the mask.

Set the initialSelectionStart parameter when calling userEvent.type to "0" in case you use showMask:

await userEvent.type(inputElement, '96051695000100', { initialSelectionStart: 0 });

Thank you for highlighting this point, we will update README.md to cover this topic.

Tsugami commented 5 months ago

Thanks, works here!