Closed Tsugami closed 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.
Thanks, works here!
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