Bird
0
0

Consider this Cypress code snippet:

medium📝 Predict Output Q13 of 15
Cypress - Assertions
Consider this Cypress code snippet:
cy.get('.todo-item').should('have.length', 4)
cy.get('.todo-item').eq(0).should('contain.text', 'Buy milk')

What will happen if the page has only 3 elements with class todo-item?
AThe first assertion fails, stopping the test; second assertion is not run.
BBoth assertions pass because the second does not depend on length.
CThe test passes but logs a warning about length mismatch.
DThe second assertion fails but the first passes.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze first assertion

    The first assertion expects 4 elements with class 'todo-item'. If only 3 exist, this assertion fails.
  2. Step 2: Understand test flow on failure

    When an assertion fails, Cypress stops the test immediately, so the second assertion is not executed.
  3. Final Answer:

    The first assertion fails, stopping the test; second assertion is not run. -> Option A
  4. Quick Check:

    Failed assertion stops test execution [OK]
Quick Trick: Failed assertions stop test; later checks won't run [OK]
Common Mistakes:
  • Assuming all assertions run despite failure
  • Thinking warnings allow test to pass
  • Confusing element count with content check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes