Skip to content

Commit

Permalink
Add tests for initialising components twice
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham authored and patrickpatrickpatrick committed Sep 11, 2024
1 parent 870fb6f commit 78d0f40
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const {
goToExample,
render,
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const { render } = require('@govuk-frontend/helpers/puppeteer')
const { getExamples } = require('@govuk-frontend/lib/components')

Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const { setTimeout } = require('timers/promises')

const { render } = require('@govuk-frontend/helpers/puppeteer')
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const {
goToExample,
getAttribute,
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const { goToExample, render } = require('@govuk-frontend/helpers/puppeteer')
const { getExamples } = require('@govuk-frontend/lib/components')

Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const { setTimeout } = require('timers/promises')

const { goToExample, render } = require('@govuk-frontend/helpers/puppeteer')
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const { render } = require('@govuk-frontend/helpers/puppeteer')
const { getExamples } = require('@govuk-frontend/lib/components')

Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const {
goToExample,
getProperty,
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-new */

const { render } = require('@govuk-frontend/helpers/puppeteer')
const { getExamples } = require('@govuk-frontend/lib/components')

Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 78d0f40

Please sign in to comment.