-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[Component Testing] checkValidity
not working on custom input elements
#19201
Comments
Even better test-case: const text = ref('')
const test = (e) => {
console.log(e.target.checkValidity())
}
mount(() => <input type="text" required minlength="4" id="test-input" onInput={ test } />)
cy.get('#test-input')
.type('h') // this isn't valid, but somehow it logs `true` |
I guess this discussion is relevant: https://stackoverflow.com/questions/66896018/html-input-checkvalidity-always-returns-true-even-with-minlength-violations And it seems to point to the issue being that JS is interacting with the field, not a user. I don't even know if there's a real way around this then. |
Alright, using |
Update: |
👋🏻 Thanks for the awesome write up @TheDutchCoder. Since you were able to isolate this bug in the driver instead of in the component testing mount layer, can you provide a minimal reproduction with e2e and we can re-purpose this issue to track the Cypress driver bug in |
This is the crux of the issue - HTML validations are ignored when using JS to update the You could try Cypress Real Events. Other than this, I don't expect this behavior is something we will be changing in the future. When you hit submit, the default HTML validation (or your own JS validation) should trigger, though, so if you are using |
Current behavior
When checking
checkValidity
inside of a custom component that uses an input, the check will always returntrue
, even when it's invalid.This might be due to attributes not properly propagating from TSX?
ChalkInput
is a Vue3 component, basically:It's almost as if events aren't sent natively from the element, because their handlers work, but the input is never actually focussed (easy to test with Tailwind classes like
focus:text-red
) and validity is never actually checked. Are certain things (like attributes) somehow stubbed?When I manually input things in the component (inside of Cypress), everything works just as expected, so it's an internal issue I think.
Desired behavior
Native (input) events to work like in the browser.
Test code to reproduce
Component:
Test:
Cypress Version
9.1.0
Other
No response
The text was updated successfully, but these errors were encountered: