Bird
0
0

Which of the following is a valid way to assert that a string variable name contains the word "Test" using expect()?

easy📝 Conceptual Q2 of 15
Cypress - Assertions
Which of the following is a valid way to assert that a string variable name contains the word "Test" using expect()?
Aexpect(name).to.include('Test')
Bexpect(name).to.equal('Test')
Cexpect(name).to.have.length(4)
Dexpect(name).to.be.true()
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct assertion for substring check

    To check if a string contains a substring, use to.include().
  2. Step 2: Eliminate other options

    to.equal() checks exact match, to.have.length() checks length, and to.be.true() is for boolean values.
  3. Final Answer:

    expect(name).to.include('Test') -> Option A
  4. Quick Check:

    Substring check = to.include() [OK]
Quick Trick: Use to.include() to check substring presence [OK]
Common Mistakes:
  • Using to.equal() for substring
  • Using to.be.true() on strings
  • Confusing length with content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes