Bird
0
0

Given this Cypress code:

hard📝 Application Q9 of 15
Cypress - Assertions
Given this Cypress code:
cy.get('.notification').should('exist').and('have.text', '')

What is the best explanation if the test fails because the element has whitespace text?
ATest fails because element is not visible
BElement does not exist in the DOM
CWhitespace is ignored by 'have.text' assertion
DThe assertion expects empty string but whitespace is not empty
Step-by-Step Solution
Solution:
  1. Step 1: Understand 'have.text' with empty string

    should('have.text', '') expects the element's text to be exactly empty, no spaces.
  2. Step 2: Consider whitespace effect

    Whitespace characters count as text, so assertion fails if element contains spaces or newlines.
  3. Final Answer:

    The assertion expects empty string but whitespace is not empty -> Option D
  4. Quick Check:

    Whitespace ≠ empty string in text assertions [OK]
Quick Trick: Trim text or check for whitespace explicitly [OK]
Common Mistakes:
  • Assuming whitespace equals empty string
  • Ignoring invisible characters in text
  • Confusing 'exist' with visibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes