2.0 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| hash | true |
Get the current URL hash. This is the same as .location().hash
Syntax
.hash(options)
Usage
.hash() cannot be chained off any other cy commands, so should be chained off of cy for clarity.
{% fa fa-check-circle green %} Valid Usage
cy.hash()
Arguments
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of .hash().
cy.hash( options )
| Option | Default | Notes |
|---|---|---|
log |
true |
whether to display command in command log |
Yields
.hash() the current URL hash as a string including the # character. If no # character is present in the URL, then an empty string will be returned.
Timeout
Examples
Hash
Assert that hash is #/users/1 given remote URL: http://localhost:8000/app/#/users/1
// Hash returns #/users/1
cy.hash().should('eq', '#/users/1') // => true
Assert that the hash matches via RegExp
<ul id="users">
<li>
<a href="#/users/8fc45b67-d2e5-465a-b822-b281d9c8e4d1">Fred</a>
</li>
</ul>
cy.get('#users li').find('a').click()
cy.hash().should('match', /users\/.+$/) // => true
Command Log
Assert that the hash matches #users/new
cy.hash().should('eq', '#users/new')
The commands above will display in the command log as:
When clicking on hash within the command log, the console outputs the following: