Bird
0
0

What is wrong with this Cypress test snippet?

medium📝 Debug Q7 of 15
Cypress - Component Testing
What is wrong with this Cypress test snippet?
const onToggle = cy.spy();
cy.mount();
cy.get('input[type="checkbox"]').check();
expect(onToggle).to.have.been.calledOnce();
AUsing check() on non-checkbox input
BUsing parentheses after calledOnce
CSpy should be reset before test
DIncorrect prop name for event handler
Step-by-Step Solution
Solution:
  1. Step 1: Review assertion syntax

    calledOnce is a property, so parentheses should not be used.
  2. Step 2: Check usage in code

    The code uses calledOnce() which causes an error since calledOnce is a property, not a function.
  3. Final Answer:

    Using parentheses after calledOnce -> Option B
  4. Quick Check:

    calledOnce is property, no parentheses [OK]
Quick Trick: Do not add parentheses after calledOnce in assertions [OK]
Common Mistakes:
  • Adding parentheses after calledOnce
  • Confusing check() usage on checkbox
  • Not resetting spy before tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes