Skip to content

Commit

Permalink
Merge pull request #4199 from alphagov/exit-this-page-missing-element
Browse files Browse the repository at this point in the history
  • Loading branch information
romaricpascal committed Sep 18, 2023
2 parents b1f93c1 + 26a179a commit d149281
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export class ExitThisPage extends GOVUKFrontendComponent {

const $button = $module.querySelector('.govuk-exit-this-page__button')
if (!($button instanceof HTMLElement)) {
return this
throw new ElementError($button, {
componentName: 'Exit this page',
identifier: 'Button',
expectedType: HTMLElement
})
}

this.config = mergeConfigs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ describe('/components/exit-this-page', () => {
message: 'Exit this page: $module is not an instance of "HTMLElement"'
})
})

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: 'ElementError',
message: 'Exit this page: Button not found'
})
})
})
})
})

0 comments on commit d149281

Please sign in to comment.