diff --git a/packages/govuk-frontend/src/govuk/components/accordion/accordion.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/accordion/accordion.puppeteer.test.js index d823c5dc09..0a866e2016 100644 --- a/packages/govuk-frontend/src/govuk/components/accordion/accordion.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/accordion/accordion.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { goToExample, render, @@ -712,6 +714,21 @@ describe('/components/accordion', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'accordion', examples.default, { + async afterInitialisation($module) { + const { Accordion } = await import('govuk-frontend') + new Accordion($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-accordion`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'accordion', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/button/button.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/button/button.puppeteer.test.js index e6b3bf6590..dda57595a9 100644 --- a/packages/govuk-frontend/src/govuk/components/button/button.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/button/button.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') @@ -329,6 +331,21 @@ describe('/components/button', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'button', examples.default, { + async afterInitialisation($module) { + const { Button } = await import('govuk-frontend') + new Button($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-button`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'button', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/character-count/character-count.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/character-count/character-count.puppeteer.test.js index f6d2c95102..4f6d7fe76a 100644 --- a/packages/govuk-frontend/src/govuk/components/character-count/character-count.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/character-count/character-count.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { setTimeout } = require('timers/promises') const { render } = require('@govuk-frontend/helpers/puppeteer') @@ -812,6 +814,21 @@ describe('Character count', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'character-count', examples.default, { + async afterInitialisation($module) { + const { CharacterCount } = await import('govuk-frontend') + new CharacterCount($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-character-count`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'character-count', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.puppeteer.test.js index fa913c9acf..fedadb067c 100644 --- a/packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { goToExample, getAttribute, @@ -367,6 +369,21 @@ describe('Checkboxes', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'checkboxes', examples.default, { + async afterInitialisation($module) { + const { Checkboxes } = await import('govuk-frontend') + new Checkboxes($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-checkboxes`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'checkboxes', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.puppeteer.test.js index e77a1c1b27..169d992756 100644 --- a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { goToExample, render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') @@ -236,6 +238,21 @@ describe('Error Summary', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'error-summary', examples.default, { + async afterInitialisation($module) { + const { ErrorSummary } = await import('govuk-frontend') + new ErrorSummary($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-error-summary`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'error-summary', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.puppeteer.test.js index cdd37cf7c8..452b206428 100644 --- a/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { setTimeout } = require('timers/promises') const { goToExample, render } = require('@govuk-frontend/helpers/puppeteer') @@ -231,6 +233,21 @@ describe('/components/exit-this-page', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'exit-this-page', examples.default, { + async afterInitialisation($module) { + const { ExitThisPage } = await import('govuk-frontend') + new ExitThisPage($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-exit-this-page`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'exit-this-page', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/header/header.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/header/header.puppeteer.test.js index fe7c0e3d55..cab35c7285 100644 --- a/packages/govuk-frontend/src/govuk/components/header/header.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/header/header.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') const { KnownDevices } = require('puppeteer') @@ -181,6 +183,21 @@ describe('Header navigation', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'header', examples.default, { + async afterInitialisation($module) { + const { Header } = await import('govuk-frontend') + new Header($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-header`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'header', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/notification-banner/notification-banner.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/notification-banner/notification-banner.puppeteer.test.js index 344d70ecc1..fd14b1d6bc 100644 --- a/packages/govuk-frontend/src/govuk/components/notification-banner/notification-banner.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/notification-banner/notification-banner.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') @@ -236,6 +238,21 @@ describe('Notification banner', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'notification-banner', examples.default, { + async afterInitialisation($module) { + const { NotificationBanner } = await import('govuk-frontend') + new NotificationBanner($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-notification-banner`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'notification-banner', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/radios/radios.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/radios/radios.puppeteer.test.js index 6a21385981..19894f62c2 100644 --- a/packages/govuk-frontend/src/govuk/components/radios/radios.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/radios/radios.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { goToExample, getProperty, @@ -320,6 +322,20 @@ describe('Radios', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'radios', examples.default, { + async afterInitialisation($module) { + const { Radios } = await import('govuk-frontend') + new Radios($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: 'Root element (`$module`) already initialised (`govuk-radios`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'radios', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/skip-link/skip-link.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/skip-link/skip-link.puppeteer.test.js index 26c30818b7..2f7764025a 100644 --- a/packages/govuk-frontend/src/govuk/components/skip-link/skip-link.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/skip-link/skip-link.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') @@ -127,6 +129,21 @@ describe('Skip Link', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'skip-link', examples.default, { + async afterInitialisation($module) { + const { SkipLink } = await import('govuk-frontend') + new SkipLink($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: + 'Root element (`$module`) already initialised (`govuk-skip-link`)' + }) + }) + it('throws when $module is not set', async () => { return expect( render(page, 'skip-link', examples.default, { diff --git a/packages/govuk-frontend/src/govuk/components/tabs/tabs.puppeteer.test.js b/packages/govuk-frontend/src/govuk/components/tabs/tabs.puppeteer.test.js index a24982d4a6..6bef0229b5 100644 --- a/packages/govuk-frontend/src/govuk/components/tabs/tabs.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/components/tabs/tabs.puppeteer.test.js @@ -1,3 +1,5 @@ +/* eslint-disable no-new */ + const { render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') const { KnownDevices } = require('puppeteer') @@ -269,6 +271,20 @@ describe('/components/tabs', () => { }) }) + it('throws when initialised twice', async () => { + await expect( + render(page, 'tabs', examples.default, { + async afterInitialisation($module) { + const { Tabs } = await import('govuk-frontend') + new Tabs($module) + } + }) + ).rejects.toMatchObject({ + name: 'InitError', + message: 'Root element (`$module`) already initialised (`govuk-tabs`)' + }) + }) + it('throws when $module is not set', async () => { await expect( render(page, 'tabs', examples.default, {