Bird
0
0

Identify the error in this Cypress test code:

medium📝 Debug Q6 of 15
Cypress - Component Testing
Identify the error in this Cypress test code:
const onSubmit = cy.spy();
cy.mount(
); cy.get('form').submit(); expect(onSubmit).to.have.been.called;
AMissing parentheses after called
Bsubmit() does not trigger onSubmit event
CSpy should be cy.stub() instead of cy.spy()
DIncorrect selector for form element
Step-by-Step Solution
Solution:
  1. Step 1: Understand form submission in Cypress

    cy.get('form').submit() triggers native submit but may not trigger React onSubmit handler.
  2. Step 2: Identify correct way to trigger onSubmit

    Triggering onSubmit usually requires clicking submit button or triggering event manually.
  3. Final Answer:

    submit() does not trigger onSubmit event -> Option B
  4. Quick Check:

    submit() native may not call React onSubmit [OK]
Quick Trick: Use button click to trigger React onSubmit, not form.submit() [OK]
Common Mistakes:
  • Assuming submit() triggers React onSubmit
  • Adding parentheses after called (called is property)
  • Confusing spy and stub usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes