Skip to content

Commit

Permalink
Only throw for section button placeholder, not button
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Oct 23, 2023
1 parent 9b811a5 commit c632049
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class Accordion extends GOVUKFrontendComponent {
if (!$span) {
throw new ElementError({
componentName: 'Accordion',
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)`
identifier: `Section button placeholder (\`<span class="${this.sectionButtonClass}">\`)`
})
}

Expand Down Expand Up @@ -411,21 +411,14 @@ export class Accordion extends GOVUKFrontendComponent {
const $button = $section.querySelector(`.${this.sectionButtonClass}`)
const $content = $section.querySelector(`.${this.sectionContentClass}`)

if (!$button) {
throw new ElementError({
componentName: 'Accordion',
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)`
})
}

if (!$content) {
throw new ElementError({
componentName: 'Accordion',
identifier: `Section content (\`<div class="${this.sectionContentClass}">\`)`
})
}

if (!$showHideIcon || !$showHideText) {
if (!$showHideIcon || !$showHideText || !$button) {
// Return early for elements we create
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ describe('/components/accordion', () => {
})
})

it('throws when any section button span is missing', async () => {
it('throws when any section button placeholder span is missing', async () => {
await expect(
render(page, 'accordion', examples.default, {
beforeInitialisation($module, { selector }) {
Expand All @@ -842,7 +842,7 @@ describe('/components/accordion', () => {
cause: {
name: 'ElementError',
message:
'Accordion: Section button (`<span class="govuk-accordion__section-button">`) not found'
'Accordion: Section button placeholder (`<span class="govuk-accordion__section-button">`) not found'
}
})
})
Expand Down

0 comments on commit c632049

Please sign in to comment.