diff --git a/package-lock.json b/package-lock.json index 02fe21df93..f57d896759 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30519,6 +30519,7 @@ "js-yaml": "^4.1.0", "minimatch": "^9.0.3", "nunjucks": "^3.2.4", + "outdent": "^0.8.0", "slash": "^3.0.0" }, "engines": { diff --git a/packages/govuk-frontend-review/src/app.mjs b/packages/govuk-frontend-review/src/app.mjs index 4d33813a5d..937b07b6de 100644 --- a/packages/govuk-frontend-review/src/app.mjs +++ b/packages/govuk-frontend-review/src/app.mjs @@ -5,7 +5,8 @@ import { getComponentsFixtures, getComponentNames, getComponentNamesFiltered, - renderComponent + render, + renderPreview } from '@govuk-frontend/lib/components' import { filterPath, hasPath } from '@govuk-frontend/lib/files' import { getStats, modulePaths } from '@govuk-frontend/stats' @@ -158,11 +159,10 @@ export default async () => { } // Construct and evaluate the component with the data for this example - res.locals.componentView = renderComponent( - componentName, - fixture.options, - { env } - ) + res.locals.componentView = render(componentName, { + context: fixture.options, + env + }) let bodyClasses = 'app-template__body' @@ -201,9 +201,11 @@ export default async () => { // Test view for injecting rendered components // and testing specific JavaScript configurations - // Example view app.get('/tests/boilerplate', function (req, res) { - res.render('tests/boilerplate') + const componentName = undefined + + // Render blank component preview + res.send(renderPreview(componentName, { env })) }) // Full page example views diff --git a/packages/govuk-frontend-review/src/common/middleware/assets.mjs b/packages/govuk-frontend-review/src/common/middleware/assets.mjs index 762f18f902..c12ca15ff2 100644 --- a/packages/govuk-frontend-review/src/common/middleware/assets.mjs +++ b/packages/govuk-frontend-review/src/common/middleware/assets.mjs @@ -19,6 +19,9 @@ const frontendPath = packageTypeToPath('govuk-frontend', { router.use('/assets', express.static(join(frontendPath, 'assets'))) router.use('/javascripts', express.static(frontendPath)) -router.use('/stylesheets', express.static(join(paths.app, 'dist/stylesheets'))) +router.use('/stylesheets', [ + express.static(frontendPath), + express.static(join(paths.app, 'dist/stylesheets')) +]) export default router diff --git a/packages/govuk-frontend-review/src/common/nunjucks/globals/get-html-code.mjs b/packages/govuk-frontend-review/src/common/nunjucks/globals/get-html-code.mjs index a0e4ca2849..1357727838 100644 --- a/packages/govuk-frontend-review/src/common/nunjucks/globals/get-html-code.mjs +++ b/packages/govuk-frontend-review/src/common/nunjucks/globals/get-html-code.mjs @@ -1,4 +1,4 @@ -import { renderComponent } from '@govuk-frontend/lib/components' +import { render } from '@govuk-frontend/lib/components' import beautify from 'js-beautify' /** @@ -6,21 +6,19 @@ import beautify from 'js-beautify' * * @this {{ env: import('nunjucks').Environment }} * @param {string} componentName - Component name - * @param {MacroOptions} [params] - Nunjucks macro options (or params) + * @param {MacroRenderOptions} [options] - Nunjucks macro render options * @returns {string} HTML rendered by the component */ -export function getHTMLCode(componentName, params) { - const html = renderComponent(componentName, params, { - env: this.env - }) +export function getHTMLCode(componentName, options) { + const html = render(componentName, { ...options, env: this.env }) // Default beautify options - const options = beautify.html.defaultOptions() + const beautifyOptions = beautify.html.defaultOptions() return beautify.html(html, { indent_size: 2, // Ensure nested labels in headings are indented properly - inline: options.inline.filter((tag) => !['label'].includes(tag)), + inline: beautifyOptions.inline.filter((tag) => !['label'].includes(tag)), // Remove blank lines max_preserve_newlines: 0, // Ensure attribute wrapping in header SVG is preserved @@ -29,5 +27,5 @@ export function getHTMLCode(componentName, params) { } /** - * @typedef {import('@govuk-frontend/lib/components').MacroOptions} MacroOptions + * @typedef {import('@govuk-frontend/lib/components').MacroRenderOptions} MacroRenderOptions */ diff --git a/packages/govuk-frontend-review/src/common/nunjucks/globals/get-nunjucks-code.mjs b/packages/govuk-frontend-review/src/common/nunjucks/globals/get-nunjucks-code.mjs index 1c2c40155f..95fc9f3a15 100644 --- a/packages/govuk-frontend-review/src/common/nunjucks/globals/get-nunjucks-code.mjs +++ b/packages/govuk-frontend-review/src/common/nunjucks/globals/get-nunjucks-code.mjs @@ -9,14 +9,14 @@ import { componentNameToMacroName } from '../filters/index.mjs' * Component Nunjucks code (formatted) * * @param {string} componentName - Component name - * @param {MacroOptions} [params] - Nunjucks macro options (or params) + * @param {MacroRenderOptions} [options] - Nunjucks macro render options * @returns {string} Nunjucks code for the component */ -export function getNunjucksCode(componentName, params) { +export function getNunjucksCode(componentName, options) { const macroName = componentNameToMacroName(componentName) // Allow nested HTML strings to wrap at `\n` - const paramsFormatted = inspect(params, { + const paramsFormatted = inspect(options.context, { compact: false, depth: Infinity, maxArrayLength: Infinity, @@ -39,5 +39,5 @@ export function getNunjucksCode(componentName, params) { } /** - * @typedef {import('@govuk-frontend/lib/components').MacroOptions} MacroOptions + * @typedef {import('@govuk-frontend/lib/components').MacroRenderOptions} MacroRenderOptions */ diff --git a/packages/govuk-frontend-review/src/views/macros/showExamples.njk b/packages/govuk-frontend-review/src/views/macros/showExamples.njk index 4ad7ad4202..b778cb8581 100644 --- a/packages/govuk-frontend-review/src/views/macros/showExamples.njk +++ b/packages/govuk-frontend-review/src/views/macros/showExamples.njk @@ -38,12 +38,16 @@ {% set codeExamplesHtml %}

Markup


-          {{- getHTMLCode(componentName, example.options) | highlight("html") | safe -}}
+          {{- getHTMLCode(componentName, {
+            context: example.options
+          }) | highlight("html") | safe -}}
         

Macro


-          {{- getNunjucksCode(componentName, example.options) | highlight("js") | safe -}}
+          {{- getNunjucksCode(componentName, {
+            context: example.options
+          }) | highlight("js") | safe -}}
         
{% endset %} diff --git a/packages/govuk-frontend-review/src/views/tests/boilerplate.njk b/packages/govuk-frontend-review/src/views/tests/boilerplate.njk deleted file mode 100644 index c7b91a372f..0000000000 --- a/packages/govuk-frontend-review/src/views/tests/boilerplate.njk +++ /dev/null @@ -1,25 +0,0 @@ -{% extends "component-preview.njk" %} - -{% set pageTitle = "Test boilerplate" %} -{% block pageTitle %}{{ pageTitle }} - GOV.UK{% endblock %} - -{% block head %} - {{ super() }} - -{% endblock %} - -{% block content %} -
-

Test boilerplate

-

- Used during testing to inject rendered components and test specific configurations -

-
-
-{% endblock %} - -{% block bodyEnd %} - -{% endblock %} 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 659c27ab00..03a86cee2c 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,7 +1,7 @@ const { goToComponent, goToExample, - renderAndInitialise, + render, getAccessibleName } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') @@ -685,7 +685,7 @@ describe('/components/accordion', () => { }) it('injects the localised strings as text not HTML', async () => { - await renderAndInitialise(page, 'accordion', examples.default, { + await render(page, 'accordion', examples.default, { config: { i18n: { showAllSections: 'Show all sections', @@ -721,7 +721,7 @@ describe('/components/accordion', () => { it('throws when GOV.UK Frontend is not supported', async () => { await expect( - renderAndInitialise(page, 'accordion', examples.default, { + render(page, 'accordion', examples.default, { beforeInitialisation() { document.body.classList.remove('govuk-frontend-supported') } @@ -734,7 +734,7 @@ describe('/components/accordion', () => { it('throws when $module is not set', async () => { await expect( - renderAndInitialise(page, 'accordion', examples.default, { + render(page, 'accordion', examples.default, { beforeInitialisation($module) { $module.remove() } @@ -747,7 +747,7 @@ describe('/components/accordion', () => { it('throws when receiving the wrong type for $module', async () => { await expect( - renderAndInitialise(page, 'accordion', examples.default, { + render(page, 'accordion', examples.default, { beforeInitialisation($module) { // Replace with an `` element which is not an `HTMLElement` in the DOM (but an `SVGElement`) $module.outerHTML = `` 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 ac0638d102..48e4cad772 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,7 +1,4 @@ -const { - goToComponent, - renderAndInitialise -} = require('@govuk-frontend/helpers/puppeteer') +const { goToComponent, render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') describe('/components/button', () => { @@ -178,7 +175,7 @@ describe('/components/button', () => { let $button beforeEach(async () => { - await renderAndInitialise(page, 'button', examples.default, { + await render(page, 'button', examples.default, { config: { preventDoubleClick: true } @@ -237,16 +234,11 @@ describe('/components/button', () => { let $button beforeEach(async () => { - await renderAndInitialise( - page, - 'button', - examples["don't prevent double click"], - { - config: { - preventDoubleClick: true - } + await render(page, 'button', examples["don't prevent double click"], { + config: { + preventDoubleClick: true } - ) + }) $button = await setButtonTracking(await page.$('button')) }) @@ -266,7 +258,7 @@ describe('/components/button', () => { let $button beforeEach(async () => { - await renderAndInitialise(page, 'button', examples.default, { + await render(page, 'button', examples.default, { config: { preventDoubleClick: true } @@ -329,7 +321,7 @@ describe('/components/button', () => { it('throws when GOV.UK Frontend is not supported', async () => { await expect( - renderAndInitialise(page, 'button', examples.default, { + render(page, 'button', examples.default, { beforeInitialisation() { document.body.classList.remove('govuk-frontend-supported') } @@ -342,7 +334,7 @@ describe('/components/button', () => { it('throws when $module is not set', async () => { await expect( - renderAndInitialise(page, 'button', examples.default, { + render(page, 'button', examples.default, { beforeInitialisation($module) { $module.remove() } @@ -355,7 +347,7 @@ describe('/components/button', () => { it('throws when receiving the wrong type for $module', async () => { await expect( - renderAndInitialise(page, 'button', examples.default, { + render(page, 'button', examples.default, { beforeInitialisation($module) { // Replace with an `` element which is not an `HTMLElement` in the DOM (but an `SVGElement`) $module.outerHTML = `` diff --git a/packages/govuk-frontend/src/govuk/components/character-count/character-count.jsdom.test.mjs b/packages/govuk-frontend/src/govuk/components/character-count/character-count.jsdom.test.mjs index 4226992a45..5a5a1c1d5d 100644 --- a/packages/govuk-frontend/src/govuk/components/character-count/character-count.jsdom.test.mjs +++ b/packages/govuk-frontend/src/govuk/components/character-count/character-count.jsdom.test.mjs @@ -1,4 +1,4 @@ -import { getExamples, renderComponent } from '@govuk-frontend/lib/components' +import { getExamples, render } from '@govuk-frontend/lib/components' import { CharacterCount } from './character-count.mjs' @@ -7,10 +7,7 @@ describe('CharacterCount', () => { beforeAll(async () => { const examples = await getExamples('character-count') - html = renderComponent( - 'character-count', - examples['to configure in JavaScript'] - ) + html = render('character-count', examples['to configure in JavaScript']) }) beforeEach(async () => { 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 40d2b47d6e..fe339cf098 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,7 +1,4 @@ -const { - goToComponent, - renderAndInitialise -} = require('@govuk-frontend/helpers/puppeteer') +const { goToComponent, render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') describe('Character count', () => { @@ -496,7 +493,7 @@ describe('Character count', () => { describe('JavaScript configuration', () => { describe('at instantiation', () => { it('configures the number of characters', async () => { - await renderAndInitialise( + await render( page, 'character-count', examples['to configure in JavaScript'], @@ -519,7 +516,7 @@ describe('Character count', () => { }) it('configures the number of words', async () => { - await renderAndInitialise( + await render( page, 'character-count', examples['to configure in JavaScript'], @@ -542,7 +539,7 @@ describe('Character count', () => { }) it('configures the threshold', async () => { - await renderAndInitialise( + await render( page, 'character-count', examples['to configure in JavaScript'], @@ -569,7 +566,7 @@ describe('Character count', () => { // This tests that a description can be provided through JavaScript attributes // and interpolated with the limit provided to the character count in JS. - await renderAndInitialise( + await render( page, 'character-count', examples[ @@ -597,7 +594,7 @@ describe('Character count', () => { describe('via `initAll`', () => { it('configures the number of characters', async () => { - await renderAndInitialise( + await render( page, 'character-count', examples['to configure in JavaScript'], @@ -620,7 +617,7 @@ describe('Character count', () => { }) it('configures the number of words', async () => { - await renderAndInitialise( + await render( page, 'character-count', examples['to configure in JavaScript'], @@ -643,7 +640,7 @@ describe('Character count', () => { }) it('configures the threshold', async () => { - await renderAndInitialise( + await render( page, 'character-count', examples['to configure in JavaScript'], @@ -669,7 +666,7 @@ describe('Character count', () => { describe('when data-attributes are present', () => { it('uses `maxlength` data attribute instead of the JS one', async () => { - await renderAndInitialise(page, 'character-count', examples.default, { + await render(page, 'character-count', examples.default, { config: { maxlength: 12 // JS configuration that would tell 1 character remaining } @@ -687,7 +684,7 @@ describe('Character count', () => { }) it("uses `maxlength` data attribute instead of JS's `maxwords`", async () => { - await renderAndInitialise(page, 'character-count', examples.default, { + await render(page, 'character-count', examples.default, { config: { maxwords: 12 } @@ -705,16 +702,11 @@ describe('Character count', () => { }) it('uses `maxwords` data attribute instead of the JS one', async () => { - await renderAndInitialise( - page, - 'character-count', - examples['with word count'], - { - config: { - maxwords: 12 // JS configuration that would tell 1 word remaining - } + await render(page, 'character-count', examples['with word count'], { + config: { + maxwords: 12 // JS configuration that would tell 1 word remaining } - ) + }) await page.type('.govuk-js-character-count', 'Hello '.repeat(11), { delay: 50 @@ -728,16 +720,11 @@ describe('Character count', () => { }) it("uses `maxwords` data attribute instead of the JS's `maxlength`", async () => { - await renderAndInitialise( - page, - 'character-count', - examples['with word count'], - { - config: { - maxlength: 10 - } + await render(page, 'character-count', examples['with word count'], { + config: { + maxlength: 10 } - ) + }) await page.type('.govuk-js-character-count', 'Hello '.repeat(11), { delay: 50 @@ -757,7 +744,7 @@ describe('Character count', () => { // element holding the textarea's accessible description // (and interpolated to replace `%{count}` with the maximum) - await renderAndInitialise( + await render( page, 'character-count', examples['when neither maxlength nor maxwords are set'], @@ -779,7 +766,7 @@ describe('Character count', () => { describe('Cross Side Scripting prevention', () => { it('injects the localised strings as text not HTML', async () => { - await renderAndInitialise( + await render( page, 'character-count', examples['to configure in JavaScript'], @@ -814,7 +801,7 @@ describe('Character count', () => { it('throws when GOV.UK Frontend is not supported', async () => { await expect( - renderAndInitialise(page, 'character-count', examples.default, { + render(page, 'character-count', examples.default, { beforeInitialisation() { document.body.classList.remove('govuk-frontend-supported') } @@ -827,7 +814,7 @@ describe('Character count', () => { it('throws when $module is not set', async () => { await expect( - renderAndInitialise(page, 'character-count', examples.default, { + render(page, 'character-count', examples.default, { beforeInitialisation($module) { $module.remove() } @@ -840,7 +827,7 @@ describe('Character count', () => { it('throws when receiving the wrong type for $module', async () => { await expect( - renderAndInitialise(page, 'character-count', examples.default, { + render(page, 'character-count', examples.default, { beforeInitialisation($module) { // Replace with an `` element which is not an `HTMLElement` in the DOM (but an `SVGElement`) $module.outerHTML = `` @@ -855,7 +842,7 @@ describe('Character count', () => { it('throws when the textarea is missing', async () => { await expect( - renderAndInitialise(page, 'character-count', examples.default, { + render(page, 'character-count', examples.default, { beforeInitialisation($module, { selector }) { $module.querySelector(selector).remove() }, @@ -872,7 +859,7 @@ describe('Character count', () => { it('throws when the textarea is not the right type', async () => { await expect( - renderAndInitialise(page, 'character-count', examples.default, { + render(page, 'character-count', examples.default, { beforeInitialisation($module, { selector }) { // Replace with a tag that's neither an `
' - } - ) + const $ = render('details', { + callBlock: '
' + }) expect($('.govuk-details .app-nested-component').length).toBeTruthy() }) 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 ce8c606a65..aa72e05b3f 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,7 +1,7 @@ const { goToComponent, goToExample, - renderAndInitialise + render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') @@ -68,7 +68,7 @@ describe('Error Summary', () => { describe('using JavaScript configuration', () => { beforeAll(async () => { - await renderAndInitialise(page, 'error-summary', examples.default, { + await render(page, 'error-summary', examples.default, { config: { disableAutoFocus: true } @@ -94,7 +94,7 @@ describe('Error Summary', () => { describe('using JavaScript configuration, but enabled via data-attributes', () => { beforeAll(async () => { - await renderAndInitialise( + await render( page, 'error-summary', examples['autofocus explicitly enabled'] @@ -118,7 +118,7 @@ describe('Error Summary', () => { describe('using `initAll`', () => { beforeAll(async () => { - await renderAndInitialise(page, 'error-summary', examples.default, { + await render(page, 'error-summary', examples.default, { config: { disableAutoFocus: true } @@ -219,7 +219,7 @@ describe('Error Summary', () => { it('throws when GOV.UK Frontend is not supported', async () => { await expect( - renderAndInitialise(page, 'error-summary', examples.default, { + render(page, 'error-summary', examples.default, { beforeInitialisation() { document.body.classList.remove('govuk-frontend-supported') } @@ -232,7 +232,7 @@ describe('Error Summary', () => { it('throws when $module is not set', async () => { await expect( - renderAndInitialise(page, 'error-summary', examples.default, { + render(page, 'error-summary', examples.default, { beforeInitialisation($module) { $module.remove() } @@ -245,7 +245,7 @@ describe('Error Summary', () => { it('throws when receiving the wrong type for $module', async () => { await expect( - renderAndInitialise(page, 'error-summary', examples.default, { + render(page, 'error-summary', examples.default, { beforeInitialisation($module) { // Replace with an `` element which is not an `HTMLElement` in the DOM (but an `SVGElement`) $module.outerHTML = `` diff --git a/packages/govuk-frontend/src/govuk/components/error-summary/template.test.js b/packages/govuk-frontend/src/govuk/components/error-summary/template.test.js index e01fa73ed3..39b17e3b2d 100644 --- a/packages/govuk-frontend/src/govuk/components/error-summary/template.test.js +++ b/packages/govuk-frontend/src/govuk/components/error-summary/template.test.js @@ -88,13 +88,9 @@ describe('Error-summary', () => { }) it('renders nested components in description using `call`', () => { - const $ = render( - 'error-summary', - {}, - { - callBlock: '
' - } - ) + const $ = render('error-summary', { + callBlock: '
' + }) expect( $('.govuk-error-summary .app-nested-component').length 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 681108b40e..0eb23d7284 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,7 +1,7 @@ const { goToComponent, goToExample, - renderAndInitialise + render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') @@ -197,7 +197,7 @@ describe('/components/exit-this-page', () => { it('throws when GOV.UK Frontend is not supported', async () => { await expect( - renderAndInitialise(page, 'exit-this-page', examples.default, { + render(page, 'exit-this-page', examples.default, { beforeInitialisation() { document.body.classList.remove('govuk-frontend-supported') } @@ -210,7 +210,7 @@ describe('/components/exit-this-page', () => { it('throws when $module is not set', async () => { await expect( - renderAndInitialise(page, 'exit-this-page', examples.default, { + render(page, 'exit-this-page', examples.default, { beforeInitialisation($module) { $module.remove() } @@ -223,7 +223,7 @@ describe('/components/exit-this-page', () => { it('throws when receiving the wrong type for $module', async () => { await expect( - renderAndInitialise(page, 'exit-this-page', examples.default, { + render(page, 'exit-this-page', examples.default, { beforeInitialisation($module) { // Replace with an `` element which is not an `HTMLElement` in the DOM (but an `SVGElement`) $module.outerHTML = `` @@ -238,7 +238,7 @@ describe('/components/exit-this-page', () => { it('throws when the button is missing', async () => { await expect( - renderAndInitialise(page, 'exit-this-page', examples.default, { + render(page, 'exit-this-page', examples.default, { beforeInitialisation($module, { selector }) { $module.querySelector(selector).remove() }, diff --git a/packages/govuk-frontend/src/govuk/components/fieldset/template.test.js b/packages/govuk-frontend/src/govuk/components/fieldset/template.test.js index da74e099d9..dfadcd6b8a 100644 --- a/packages/govuk-frontend/src/govuk/components/fieldset/template.test.js +++ b/packages/govuk-frontend/src/govuk/components/fieldset/template.test.js @@ -73,13 +73,9 @@ describe('fieldset', () => { }) it('renders nested components using `call`', () => { - const $ = render( - 'fieldset', - {}, - { - callBlock: '
' - } - ) + const $ = render('fieldset', { + callBlock: '
' + }) expect($('.govuk-fieldset .app-nested-component').length).toBeTruthy() }) 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 2513c23190..fbfa3e4c70 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,7 +1,4 @@ -const { - goToComponent, - renderAndInitialise -} = require('@govuk-frontend/helpers/puppeteer') +const { goToComponent, render } = require('@govuk-frontend/helpers/puppeteer') const { getExamples } = require('@govuk-frontend/lib/components') const { KnownDevices } = require('puppeteer') @@ -177,7 +174,7 @@ describe('Header navigation', () => { it('throws when GOV.UK Frontend is not supported', async () => { await expect( - renderAndInitialise(page, 'header', examples.default, { + render(page, 'header', examples.default, { beforeInitialisation() { document.body.classList.remove('govuk-frontend-supported') } @@ -190,7 +187,7 @@ describe('Header navigation', () => { it('throws when $module is not set', async () => { await expect( - renderAndInitialise(page, 'header', examples.default, { + render(page, 'header', examples.default, { beforeInitialisation($module) { // Remove the root of the components as a way // for the constructor to receive the wrong type for `$module` @@ -208,12 +205,12 @@ describe('Header navigation', () => { // and should keep rendering. No expectations as the JavaScript // will just return early. All we ask of that test is for it not // to throw during the initialisation - await renderAndInitialise(page, 'header', examples.default) + await render(page, 'header', examples.default) }) it("throws when the toggle's aria-control attribute is missing", async () => { await expect( - renderAndInitialise(page, 'header', examples['with navigation'], { + render(page, 'header', examples['with navigation'], { beforeInitialisation($module, { selector }) { $module.querySelector(selector).removeAttribute('aria-controls') }, @@ -230,7 +227,7 @@ describe('Header navigation', () => { it('throws when the menu is missing, but a toggle is present', async () => { await expect( - renderAndInitialise(page, 'header', examples['with navigation'], { + render(page, 'header', examples['with navigation'], { beforeInitialisation($module, { selector }) { // Remove the menu `