user-event icon indicating copy to clipboard operation
user-event copied to clipboard

Update ValidityState when editing values

Open ph-fritsche opened this issue 4 years ago • 2 comments

Problem description:

When changing an element in UI, the browser updates element.validity. user-event maintains the UI value as it diverges from the IDL value, but it does not update element.validity accordingly.

There was a test asserting this behavior: https://github.com/testing-library/user-event/blob/a747b0ab07681651bf6b6428471de2dd76bc22df/tests/type/index.ts#L531-L542

Suggested solution:

Implement ValidityState and update it when changing UI value.

ph-fritsche avatar Dec 08 '21 21:12 ph-fritsche

My team is also suffering with this problem on a HTML 5 date field. In the browser you can partially fill out a date whereas in react testing library we can only input complete dates.

We have worked around the problem by extracting the function and testing it in isolation but its not an ideal solution.

kmaid avatar Jun 28 '22 13:06 kmaid

// THIS IS A LIMITATION OF THE BROWSER // It is impossible to programmatically set an input // value to an invlid value. Not sure how to work around this

I don't know if that would help but the customError member of ValidiyState can be set through setCustomValidity

challet avatar Jan 11 '23 12:01 challet