From 9af37d90e526e3913550c714584a775294ae742e Mon Sep 17 00:00:00 2001 From: Patrick Cartlidge Date: Mon, 19 Aug 2024 11:27:24 +0100 Subject: [PATCH] Add `isSupported` to `all.mjs` - adds `isSupported` as an export for import from `govuk-frontend` - removes `internal` from JSDoc to mark function as public - adds `exports isSupported function` test - updates `exports Components` test --- packages/govuk-frontend/src/govuk/all.mjs | 1 + .../src/govuk/all.puppeteer.test.js | 16 +++++++++++++++- .../govuk-frontend/src/govuk/common/index.mjs | 3 +-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/govuk-frontend/src/govuk/all.mjs b/packages/govuk-frontend/src/govuk/all.mjs index c4eec04427..d062f11c2d 100644 --- a/packages/govuk-frontend/src/govuk/all.mjs +++ b/packages/govuk-frontend/src/govuk/all.mjs @@ -12,6 +12,7 @@ export { Radios } from './components/radios/radios.mjs' export { SkipLink } from './components/skip-link/skip-link.mjs' export { Tabs } from './components/tabs/tabs.mjs' export { initAll, createAll } from './init.mjs' +export { isSupported } from './common/index.mjs' /** * @typedef {import('./init.mjs').Config} Config diff --git a/packages/govuk-frontend/src/govuk/all.puppeteer.test.js b/packages/govuk-frontend/src/govuk/all.puppeteer.test.js index 7b1bd680b4..fd9c2ce8e2 100644 --- a/packages/govuk-frontend/src/govuk/all.puppeteer.test.js +++ b/packages/govuk-frontend/src/govuk/all.puppeteer.test.js @@ -41,10 +41,24 @@ describe('GOV.UK Frontend', () => { expect(typeofCreateAll).toBe('function') }) + it('exports `isSupported` function', async () => { + const typeofIsSupported = await page.evaluate( + async (importPath, exportName) => { + const namespace = await import(importPath) + return typeof namespace[exportName] + }, + scriptsPath.href, + 'isSupported' + ) + + expect(typeofIsSupported).toBe('function') + }) + it('exports Components', async () => { const components = exported .filter( - (method) => !['initAll', 'createAll', 'version'].includes(method) + (method) => + !['initAll', 'createAll', 'version', 'isSupported'].includes(method) ) .sort() diff --git a/packages/govuk-frontend/src/govuk/common/index.mjs b/packages/govuk-frontend/src/govuk/common/index.mjs index d2e18910b1..60699f4088 100644 --- a/packages/govuk-frontend/src/govuk/common/index.mjs +++ b/packages/govuk-frontend/src/govuk/common/index.mjs @@ -194,8 +194,7 @@ export function setFocus($element, options = {}) { * Some browsers will load and run our JavaScript but GOV.UK Frontend * won't be supported. * - * @internal - * @param {HTMLElement | null} [$scope] - HTML element `` checked for browser support + * @param {HTMLElement | null} [$scope] - (internal) `` HTML element checked for browser support * @returns {boolean} Whether GOV.UK Frontend is supported on this page */ export function isSupported($scope = document.body) {