--- title: hash comments: true description: '' --- Get the current URL hash. This is the same as [`cy.location().hash`](https://on.cypress.io/api/location) | | | |--- | --- | | **Returns** | the current URL hash as a string, including the `#` character. If no `#` character is present, an empty string will be returned. | | **Timeout** | *cannot timeout* | # [cy.hash()](#usage) Get the current URL hash. # Options Pass in an options object to change the default behavior of `cy.hash`. **cy.hash( *options* )** **cy.hash( *options* )** Option | Default | Notes --- | --- | --- `log` | `true` | whether to display command in command log # Usage ## Assert that the hash is `#/users/1` given the remote URL: `http://localhost:8000/app/#/users/1` ```javascript // Hash returns #/users/1 cy.hash().should('eq', '#/users/1') // => true ``` ## Assert that the hash matches via RegExp ```html ``` ```javascript cy .get('#users li').find('a') .hash().should('match', /users\/.+$/) // => true ``` # Notes ## Hash is a shortcut for `cy.location().hash` These 3 assertions are all the same. ```javascript // 1. verbose cy.location().then(function(location){ expect(location.hash).to.eq('#/users/1') }) // 2. better cy.location().its('hash').should('eq', '#/users/1') // 3. best cy.hash().should('eq', '#/users/1') ``` # Command Log ## Assert that the hash matches `#users/new` ```javascript cy.hash().should('eq', '#users/new') ``` The commands above will display in the command log as: screen shot 2015-11-29 at 1 34 12 pm When clicking on `hash` within the command log, the console outputs the following: screen shot 2015-11-29 at 1 34 17 pm # See also - [location](https://on.cypress.io/api/location) - [url](https://on.cypress.io/api/url)