Skip to content

Commit

Permalink
Fix race condition in Accordion accessible name test
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Dec 8, 2022
1 parent f2d3eac commit 68e7715
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/puppeteer-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ function getAttribute ($element, attributeName) {
/**
* Gets the accessible name of the given element, if it exists in the accessibility tree
*
* @param {import('puppeteer').Page} page - Puppeteer page object
* @param {import('puppeteer').ElementHandle} $element - Puppeteer element handle
* @returns {string} The element's accessible name
* @throws {TypeError} If the element has no corresponding node in the accessibility tree
*/
async function getAccessibleName ($element) {
async function getAccessibleName (page, $element) {
// Purposefully doesn't use `?.` to return undefined if there's no node in the
// accessibility tree. This lets us distinguish different kinds of failures:
// - assertion on the name failing: we need to figure out
Expand Down
8 changes: 4 additions & 4 deletions src/govuk/components/accordion/accordion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ describe('/components/accordion', () => {

const $element = await page.$('.govuk-accordion__section-button')

expect(getAccessibleName($element)).resolves.toBe(
await expect(getAccessibleName(page, $element)).resolves.toBe(
'Section A , Show this section'
)

await $element.click()

expect(getAccessibleName($element)).resolves.toBe(
await expect(getAccessibleName(page, $element)).resolves.toBe(
'Section A , Hide this section'
)
})
Expand All @@ -269,13 +269,13 @@ describe('/components/accordion', () => {

const $element = await page.$('.govuk-accordion__section-button')

expect(getAccessibleName($element)).resolves.toBe(
await expect(getAccessibleName(page, $element)).resolves.toBe(
'Test , Additional description , Show this section'
)

await $element.click()

expect(getAccessibleName($element)).resolves.toBe(
await expect(getAccessibleName(page, $element)).resolves.toBe(
'Test , Additional description , Hide this section'
)
})
Expand Down

0 comments on commit 68e7715

Please sign in to comment.