Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty state urls in navigation #20948

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -25,6 +26,11 @@ export const historyNavigationTriggeredHashChange = (state): boolean => {
}

const urls = state('urls')

if (_.isEmpty(urls)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's explicitly check for a urlPosition value here too before continuing on. Your second spec asserts that it doesn't throw without a value, but the logic that follows isn't very meaningful without one.

return false
}

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

Expand Down