Skip to content

Commit

Permalink
Throw MissingElementError when "Exit this page" button is missing
Browse files Browse the repository at this point in the history
Wording to match that of the Skip link component, but to be reviewed in #4072.

Closes #4129
  • Loading branch information
romaricpascal committed Sep 11, 2023
1 parent 00c79a9 commit e532cb5
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,5 +1,6 @@
import { mergeConfigs, extractConfigByNamespace } from '../../common/index.mjs'
import { normaliseDataset } from '../../common/normalise-dataset.mjs'
import { MissingElementError } from '../../errors/index.mjs'
import { GOVUKFrontendComponent } from '../../govuk-frontend-component.mjs'
import { I18n } from '../../i18n.mjs'

Expand Down Expand Up @@ -86,7 +87,7 @@ export class ExitThisPage extends GOVUKFrontendComponent {

const $button = $module.querySelector('.govuk-exit-this-page__button')
if (!($button instanceof HTMLElement)) {
return this
throw new MissingElementError('Exit this page: Button not found')
}

this.config = mergeConfigs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ describe('/components/exit-this-page', () => {
message: 'GOV.UK Frontend is not supported in this browser'
})
})

it('throws when the button is missing', async () => {
await expect(
renderAndInitialise(page, 'exit-this-page', {
params: examples.default,
beforeInitialisation($module) {
$module.querySelector('.govuk-exit-this-page__button').remove()
}
})
).rejects.toEqual({
name: 'MissingElementError',
message: 'Exit this page: Button not found'
})
})
})
})
})

0 comments on commit e532cb5

Please sign in to comment.