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

Update ValidityState when editing values #801

Open
ph-fritsche opened this issue Dec 8, 2021 · 2 comments
Open

Update ValidityState when editing values #801

ph-fritsche opened this issue Dec 8, 2021 · 2 comments
Labels
accuracy Improves the accuracy of how behavior is simulated enhancement New feature or request

Comments

@ph-fritsche
Copy link
Member

ph-fritsche commented Dec 8, 2021

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:

test('typing an invalid input value', async () => {
const {element} = setup<HTMLInputElement>('<input type="number" />')
await userEvent.type(element, '3-3')
expect(element).toHaveValue(null)
// 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
// but the badInput should actually be "true" if the user types "3-3"
expect(element.validity.badInput).toBe(false)
})

Suggested solution:

Implement ValidityState and update it when changing UI value.

@ph-fritsche ph-fritsche added enhancement New feature or request accuracy Improves the accuracy of how behavior is simulated labels Dec 8, 2021
@kmaid
Copy link

kmaid commented Jun 28, 2022

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.

@challet
Copy link

challet commented Jan 11, 2023

// 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accuracy Improves the accuracy of how behavior is simulated enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants