GoncharukOrg / react-input

111 stars 9 forks source link

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

Closed Tsugami closed 7 months ago

Tsugami commented 7 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 7 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 7 months ago

Thanks, works here!