Bird
0
0

You want to verify that the current URL path starts with /user and the query string contains id=42. Which Cypress code correctly does this?

hard📝 Application Q8 of 15
Cypress - Navigation and URL
You want to verify that the current URL path starts with /user and the query string contains id=42. Which Cypress code correctly does this?
Acy.location('pathname').should('include', '/user').and('include', 'id=42')
Bcy.location('pathname').should('match', /^\/user/).then(() => cy.location('search').should('include', 'id=42'))
Ccy.location('host').should('eq', '/user').and('include', 'id=42')
Dcy.location('search').should('eq', '/user?id=42')
Step-by-Step Solution
Solution:
  1. Step 1: Check pathname starts with '/user'

    Use regex with 'match' to verify pathname starts with '/user'.
  2. Step 2: Verify query string contains 'id=42'

    Use 'include' on 'search' to check query string contains 'id=42'.
  3. Step 3: Confirm chaining and correctness

    cy.location('pathname').should('match', /^\/user/).then(() => cy.location('search').should('include', 'id=42')) correctly separates checks and uses proper assertions.
  4. Final Answer:

    cy.location('pathname').should('match', /^\/user/).then(() => cy.location('search').should('include', 'id=42')) -> Option B
  5. Quick Check:

    Use regex for path and include for query [OK]
Quick Trick: Use regex with 'match' for path start checks [OK]
Common Mistakes:
  • Using 'include' on pathname for start check
  • Checking host instead of pathname
  • Comparing search to full path string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes