Bird
0
0

You want to verify a list of items where each item must be visible and contain the word 'Task'. Which chained assertion is correct?

hard📝 Application Q8 of 15
Cypress - Assertions
You want to verify a list of items where each item must be visible and contain the word 'Task'. Which chained assertion is correct?
Acy.get('.list-item').each(($el) => { cy.wrap($el).should('be.visible').and('contain', 'Task') })
Bcy.get('.list-item').should('be.visible').and('contain', 'Task')
Ccy.get('.list-item').should('have.length.greaterThan', 0).and('contain', 'Task')
Dcy.get('.list-item').each(($el) => { cy.wrap($el).should('contain', 'Task').and('be.visible') })
Step-by-Step Solution
Solution:
  1. Step 1: Understand per-element assertions

    To check each item individually, use .each() with wrapped element assertions.
  2. Step 2: Verify correct chaining inside each

    cy.get('.list-item').each(($el) => { cy.wrap($el).should('be.visible').and('contain', 'Task') }) correctly wraps each element and chains be.visible and contain assertions.
  3. Final Answer:

    cy.get('.list-item').each(($el) => { cy.wrap($el).should('be.visible').and('contain', 'Task') }) -> Option A
  4. Quick Check:

    Use .each() with wrapped assertions for per-item checks [OK]
Quick Trick: Use .each() and cy.wrap() for assertions on each element [OK]
Common Mistakes:
  • Assuming .should() applies to all elements individually
  • Not wrapping elements inside .each()
  • Using .should() without .each() for per-item checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes