Skip to content

Commit

Permalink
Throw MissingElementError if key HTML missing
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Sep 5, 2023
1 parent 462146a commit b56cebf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MissingElementError } from '../../errors/index.mjs'
import { GOVUKFrontendComponent } from '../../govuk-frontend-component.mjs'

/**
Expand Down Expand Up @@ -33,7 +34,7 @@ export class SkipLink extends GOVUKFrontendComponent {
// Check for linked element
const $linkedElement = this.getLinkedElement()
if (!$linkedElement) {
return
throw new MissingElementError('The linked HTML element does not exist')
}

this.$linkedElement = $linkedElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,19 @@ describe('Skip Link', () => {
message: 'GOV.UK Frontend is not supported in this browser'
})
})

it('throws when the linked element is missing', async () => {
await expect(
renderAndInitialise(page, 'skip-link', {
params: {
text: 'Skip to main content',
href: '#this-element-does-not-exist'
}
})
).rejects.toEqual({
name: 'MissingElementError',
message: 'The linked HTML element does not exist'
})
})
})
})

0 comments on commit b56cebf

Please sign in to comment.