Skip to content

Commit

Permalink
fix: empty state urls in navigation (#20948)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-short committed Apr 8, 2022
1 parent d5c033f commit 95feb15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/driver/cypress/integration/cy/navigation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ describe('cy/navigation', () => {
expect(triggeredHashChange).to.be.false
})

it('when no urls or urlPosition in state', () => {
const state = $SetterGetter.create({
navHistoryDelta: 1,
})

const triggeredHashChange = historyNavigationTriggeredHashChange(state)

expect(triggeredHashChange).to.be.false
})

it('when no urlPosition in state', () => {
const state = $SetterGetter.create({
navHistoryDelta: 1,
url: 'https://my_url.com/',
urls: ['https://my_url.com/', 'https://my_url.com/home'],
})

const triggeredHashChange = historyNavigationTriggeredHashChange(state)

expect(triggeredHashChange).to.be.false
})

it('when neither url has a hash', () => {
const state = $SetterGetter.create({
navHistoryDelta: 1,
Expand Down
6 changes: 6 additions & 0 deletions packages/driver/src/cy/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash'
import { $Location } from '../cypress/location'

export const bothUrlsMatchAndOneHasHash = (current, remote, eitherShouldHaveHash: boolean = false): boolean => {
Expand Down Expand Up @@ -26,6 +27,11 @@ export const historyNavigationTriggeredHashChange = (state): boolean => {

const urls = state('urls')
const urlPosition = state('urlPosition')

if (_.isEmpty(urls) || urlPosition === undefined) {
return false
}

const currentUrl = $Location.create(urls[urlPosition])

const nextPosition = urlPosition + delta
Expand Down

3 comments on commit 95feb15

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 95feb15 Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.4/linux-x64/develop-95feb15e30aaadb991e236946160275f8b30b0dc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 95feb15 Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.4/darwin-x64/develop-95feb15e30aaadb991e236946160275f8b30b0dc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 95feb15 Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.4/win32-x64/develop-95feb15e30aaadb991e236946160275f8b30b0dc/cypress.tgz

Please sign in to comment.