Bird
0
0

Consider the following Cypress code:

medium📝 Predict Output Q4 of 15
Cypress - Assertions
Consider the following Cypress code:
cy.get('.notification').should('not.have.class', 'active')

What will happen if the element .notification has the class active?
AThe test will pass because 'not.have.class' ignores classes
BThe test will pass because the element exists
CThe test will fail because the element does not exist
DThe test will fail because the element has the 'active' class
Step-by-Step Solution
Solution:
  1. Step 1: Understand the assertion

    The assertion should('not.have.class', 'active') checks that the element does NOT have the class 'active'.
  2. Step 2: Analyze the element state

    If the element actually has the class 'active', the assertion fails because the negative condition is violated.
  3. Final Answer:

    The test will fail because the element has the 'active' class -> Option D
  4. Quick Check:

    Negative class assertion fails if class present = D [OK]
Quick Trick: Negative class check fails if class is present [OK]
Common Mistakes:
  • Assuming test passes if element exists
  • Confusing class presence with existence
  • Thinking 'not.have.class' ignores classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes