Bird
0
0

You wrote cy.location('hash').should('eq', 'details') to check the URL hash #details. Why does this test fail?

medium📝 Debug Q14 of 15
Cypress - Navigation and URL
You wrote cy.location('hash').should('eq', 'details') to check the URL hash #details. Why does this test fail?
ABecause <code>should('eq')</code> cannot compare strings
BBecause <code>cy.location('hash')</code> returns the pathname, not the hash
CBecause the hash value includes the <code>#</code> symbol, so it should be <code>'#details'</code>
DBecause the hash is not part of the URL
Step-by-Step Solution
Solution:
  1. Step 1: Understand what cy.location('hash') returns

    It returns the hash part of the URL including the # symbol, e.g., #details.
  2. Step 2: Check the assertion value

    The test compares to 'details' without #, so it fails because the strings don't match exactly.
  3. Final Answer:

    The hash value includes the # symbol, so it should be '#details' -> Option C
  4. Quick Check:

    Hash includes '#' in cy.location('hash') [OK]
Quick Trick: Include '#' when asserting hash values [OK]
Common Mistakes:
  • Forgetting '#' in hash comparison
  • Confusing hash with pathname
  • Using wrong assertion method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes