なんだかGoodVibes

日々の勉強メモです。

【Cypress】window.locationを検証する(location)

こんにちは。 本日はCypressメモです。

概要

該当のページのwindow.locationの内容を検証したい。


Cypress

.location()でwindow.locationの値を取得することができます。
検証したい項目を指定して検証を実施します。

describe('サンプル', () => {
    it('テストパターン', () => {
        cy.visit('/')

        cy.location().should(loc => {
            expect(loc.host).to.eq('localhost:8080')
            expect(loc.hostname).to.eq('localhost')
            expect(loc.port).to.eq('8080')
            expect(loc.protocol).to.eq('http:')
        })
    })
})

検証可能な項目は、上記以外にもあり、
以下の項目となっています。

  • hash
  • host
  • hostname
  • href
  • origin
  • pathname
  • port
  • protocol
  • search
  • toString



以上です