Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Jul 26, 2023
1 parent c1d6bdc commit 4ae0af5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('/components/button', () => {

// `undefined` simulates the element being missing,
// from an unchecked `document.querySelector` for example
new namespace[exportName](undefined).init()
/* eslint-disable-next-line no-new */
new namespace[exportName](undefined)

// If our component initialisation breaks, this won't run
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ describe('Error Summary', () => {

// `undefined` simulates the element being missing,
// from an unchecked `document.querySelector` for example
new namespace[exportName](undefined).init()
/* eslint-disable-next-line no-new */
new namespace[exportName](undefined)

// If our component initialisation breaks, this won't run
return true
Expand Down
16 changes: 0 additions & 16 deletions packages/govuk-frontend/src/govuk/components/globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ describe('GOV.UK Frontend', () => {
])
})

it('exported Components have an init function', async () => {
const components = exported
.filter(method => !['initAll', 'version'].includes(method))

const componentsWithoutInitFunctions = await page.evaluate(async (components) => {
const namespace = await import('govuk-frontend')

return components.filter(component => {
const prototype = namespace[component].prototype
return typeof prototype.init !== 'function'
})
}, components)

expect(componentsWithoutInitFunctions).toEqual([])
})

it('can be initialised scoped to certain sections of the page', async () => {
await goToExample(page, 'scoped-initialisation')

Expand Down
5 changes: 3 additions & 2 deletions shared/helpers/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function axe (page, overrides = {}) {
* the test boilerplate page, then either:
*
* - instantiates the component class, passing the provided JavaScript
* configuration, and calls the init function
* configuration
* - runs the passed initialiser function inside the browser
* (which lets you instantiate it a different way, like using `initAll`,
* or run arbitrary code)
Expand Down Expand Up @@ -100,7 +100,8 @@ async function renderAndInitialise (page, componentName, options) {
}

const namespace = await import('govuk-frontend')
new namespace[exportName]($module, options.config).init()
/* eslint-disable-next-line no-new */
new namespace[exportName]($module, options.config)
}, componentNameToClassName(componentName), options)

return page
Expand Down

0 comments on commit 4ae0af5

Please sign in to comment.