location.spec.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. /// <reference types="cypress" />
  2. context('Location', () => {
  3. beforeEach(() => {
  4. cy.visit('https://example.cypress.io/commands/location')
  5. })
  6. it('cy.hash() - get the current URL hash', () => {
  7. // https://on.cypress.io/hash
  8. cy.hash().should('be.empty')
  9. })
  10. it('cy.location() - get window.location', () => {
  11. // https://on.cypress.io/location
  12. cy.location().should((location) => {
  13. expect(location.hash).to.be.empty
  14. expect(location.href).to.eq('https://example.cypress.io/commands/location')
  15. expect(location.host).to.eq('example.cypress.io')
  16. expect(location.hostname).to.eq('example.cypress.io')
  17. expect(location.origin).to.eq('https://example.cypress.io')
  18. expect(location.pathname).to.eq('/commands/location')
  19. expect(location.port).to.eq('')
  20. expect(location.protocol).to.eq('https:')
  21. expect(location.search).to.be.empty
  22. })
  23. })
  24. it('cy.url() - get the current URL', () => {
  25. // https://on.cypress.io/url
  26. cy.url().should('eq', 'https://example.cypress.io/commands/location')
  27. })
  28. })