Bird
0
0

You want to assert that an array items contains exactly 3 elements and includes the string "book". Which of the following is the correct way to write this using expect()?

hard📝 Application Q8 of 15
Cypress - Assertions
You want to assert that an array items contains exactly 3 elements and includes the string "book". Which of the following is the correct way to write this using expect()?
Aexpect(items).to.have.length(3).include('book')
Bexpect(items).to.have.length(3).and.include('book')
Cexpect(items).to.have.lengthOf(3).and.to.include('book')
Dexpect(items).to.include('book').and.to.have.length(3)
Step-by-Step Solution
Solution:
  1. Step 1: Check chaining syntax for length and inclusion

    Chaining with .and. is correct to combine assertions.
  2. Step 2: Verify method names and order

    to.have.length(3) and include('book') are valid; chaining order is flexible but .and. is needed.
  3. Final Answer:

    expect(items).to.have.length(3).and.include('book') -> Option B
  4. Quick Check:

    Use .and. to chain multiple expect assertions [OK]
Quick Trick: Chain assertions with .and. for multiple checks [OK]
Common Mistakes:
  • Missing .and. between assertions
  • Using lengthOf instead of length
  • Wrong chaining order without .and.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes