Skip to content

Commit 95feb15

Browse files
authored
fix: empty state urls in navigation (#20948)
1 parent d5c033f commit 95feb15

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packages/driver/cypress/integration/cy/navigation_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,28 @@ describe('cy/navigation', () => {
146146
expect(triggeredHashChange).to.be.false
147147
})
148148

149+
it('when no urls or urlPosition in state', () => {
150+
const state = $SetterGetter.create({
151+
navHistoryDelta: 1,
152+
})
153+
154+
const triggeredHashChange = historyNavigationTriggeredHashChange(state)
155+
156+
expect(triggeredHashChange).to.be.false
157+
})
158+
159+
it('when no urlPosition in state', () => {
160+
const state = $SetterGetter.create({
161+
navHistoryDelta: 1,
162+
url: 'https://my_url.com/',
163+
urls: ['https://my_url.com/', 'https://my_url.com/home'],
164+
})
165+
166+
const triggeredHashChange = historyNavigationTriggeredHashChange(state)
167+
168+
expect(triggeredHashChange).to.be.false
169+
})
170+
149171
it('when neither url has a hash', () => {
150172
const state = $SetterGetter.create({
151173
navHistoryDelta: 1,

packages/driver/src/cy/navigation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash'
12
import { $Location } from '../cypress/location'
23

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

2728
const urls = state('urls')
2829
const urlPosition = state('urlPosition')
30+
31+
if (_.isEmpty(urls) || urlPosition === undefined) {
32+
return false
33+
}
34+
2935
const currentUrl = $Location.create(urls[urlPosition])
3036

3137
const nextPosition = urlPosition + delta

0 commit comments

Comments
 (0)