Bird
0
0

Identify the error in this Cypress code snippet:

medium📝 Debug Q14 of 15
Cypress - Assertions
Identify the error in this Cypress code snippet:
cy.get('.btn').and('be.enabled').should('have.text', 'Submit')
AUsing .and() before .should() causes a syntax error.
BThe selector '.btn' is invalid.
CThe assertion 'have.text' is not supported.
DNo error; code is correct.
Step-by-Step Solution
Solution:
  1. Step 1: Check chaining order

    Chaining must start with .should(). Using .and() first is invalid syntax.
  2. Step 2: Validate other parts

    Selector '.btn' is valid CSS class selector. 'have.text' is a valid assertion. So no error there.
  3. Final Answer:

    Using .and() before .should() causes a syntax error. -> Option A
  4. Quick Check:

    Start chain with .should(), not .and() [OK]
Quick Trick: Always start assertions with .should() [OK]
Common Mistakes:
  • Starting chain with .and()
  • Confusing selector syntax
  • Misunderstanding assertion names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes