Skip to content

Commit

Permalink
Give expectedType a default value
Browse files Browse the repository at this point in the history
  • Loading branch information
romaricpascal authored and colinrotherham committed Sep 18, 2023
1 parent 70e1277 commit 1deaeb0
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ export class Accordion extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Accordion',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export class Button extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Button',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ export class CharacterCount extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Character count',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class Checkboxes extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Checkboxes',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export class ErrorSummary extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Error summary',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export class ExitThisPage extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Exit this page',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export class Header extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Header',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export class NotificationBanner extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Notification banner',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class Radios extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Radios',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
3 changes: 1 addition & 2 deletions packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export class Tabs extends GOVUKFrontendComponent {
if (!($module instanceof HTMLElement)) {
throw new ElementError($module, {
componentName: 'Tabs',
identifier: '$module',
expectedType: HTMLElement
identifier: '$module'
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/govuk-frontend/src/govuk/errors/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export class ElementError extends GOVUKFrontendError {
* @param {string} options.identifier - An identifier that'll let the user understand which element has an error (variable name, CSS selector)
* @param {typeof HTMLElement} [options.expectedType] - The type that was expected for the element
*/
constructor(element, { componentName, identifier, expectedType }) {
constructor(
element,
{ componentName, identifier, expectedType = HTMLElement }
) {
const reason = !element
? `${identifier} not found`
: `${identifier} is not an instance of "${expectedType.name}"`
Expand Down

0 comments on commit 1deaeb0

Please sign in to comment.