Replies: 3 comments
|
A few cases where you can see no errors and still have
In E2E tests this is especially common with So I’d first check the form mode and whether Cypress is reproducing the same blur/change sequence as a real user. |
|
Yeah, this is a classic race condition often seen in fast automation environments like Cypress. The reason is that When you see First, make sure you are actually destructuring // This destructuring is required for subscription
const { formState: { isValid, errors } } = useForm({
mode: 'onChange'
});For Cypress specifically, stop checking the // ❌ Avoid checking raw state
// expect(formState.isValid).to.be.true;
// ✅ Assert on the UI
cy.get('input[name="email"]').type('test@example.com');
cy.get('button[type="submit"]').should('not.be.disabled');If you really need the state, you can wait for the validation to settle by checking |
|
One useful way to narrow this down is to distinguish an actual validation failure from a form-state subscription or event-sequencing issue. I would check three things:
For the Cypress test, prefer a retryable DOM assertion: cy.get('[name="email"]').type('test@example.com').blur(); If an explicit "trigger()" resolves the discrepancy, investigate the event sequence and validation mode. If it does not, a minimal reproduction with the resolver and default values would help isolate the remaining issue. Also, "errors" being empty is not, by itself, proof that the complete form has passed validation. |
Uh oh!
There was an error while loading. Please reload this page.
Just need to know - under what conditions after validation has succeeded and there are no errors, can
isValidremainfalse?This problem (if it's a problem) occurs only when filling out a form with Cypress, but not manually. This makes me suspect a race condition. But why can I see
isValidatinggoing fromtrueand back tofalse, produce no errors, and keepisValidatfalse? How? Why?All reactions