From 4ae0af5a37797526016d6362b2e6c8263179421c Mon Sep 17 00:00:00 2001 From: Brett Kyle Date: Wed, 26 Jul 2023 12:50:42 +0100 Subject: [PATCH] Update tests --- .../src/govuk/components/button/button.test.js | 3 ++- .../error-summary/error-summary.test.js | 3 ++- .../src/govuk/components/globals.test.js | 16 ---------------- shared/helpers/puppeteer.js | 5 +++-- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/packages/govuk-frontend/src/govuk/components/button/button.test.js b/packages/govuk-frontend/src/govuk/components/button/button.test.js index f0c507380c..d06737b5f5 100644 --- a/packages/govuk-frontend/src/govuk/components/button/button.test.js +++ b/packages/govuk-frontend/src/govuk/components/button/button.test.js @@ -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 diff --git a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.test.js b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.test.js index 9321e1a1e1..6c779bd1d3 100644 --- a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.test.js +++ b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.test.js @@ -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 diff --git a/packages/govuk-frontend/src/govuk/components/globals.test.js b/packages/govuk-frontend/src/govuk/components/globals.test.js index 2267ab63d1..f412f8bf90 100644 --- a/packages/govuk-frontend/src/govuk/components/globals.test.js +++ b/packages/govuk-frontend/src/govuk/components/globals.test.js @@ -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') diff --git a/shared/helpers/puppeteer.js b/shared/helpers/puppeteer.js index f44298bc03..6d8aab17ea 100644 --- a/shared/helpers/puppeteer.js +++ b/shared/helpers/puppeteer.js @@ -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) @@ -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