Bird
0
0

Given this Cypress test snippet:

medium📝 Predict Output Q13 of 15
Cypress - Component Testing
Given this Cypress test snippet:
const onClick = cy.spy();
cy.mount(

What will be the test result?
ATest passes because the click triggers onClick once
BTest passes but onClick is called multiple times
CTest fails because onClick is never called
DTest fails due to syntax error in expect statement
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the spy and mount setup

    onClick is a spy passed as prop; Button is mounted with it.
  2. Step 2: Check the assertion syntax

    The assertion uses calledOnce() which is incorrect syntax; it should be calledOnce without parentheses.
  3. Final Answer:

    Test fails due to syntax error in expect statement -> Option D
  4. Quick Check:

    calledOnce() is invalid syntax [OK]
Quick Trick: Use calledOnce without () in assertions [OK]
Common Mistakes:
  • Adding parentheses after calledOnce
  • Assuming spy is not called when it is
  • Ignoring syntax errors in assertions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes