Skip to content

Commit

Permalink
Merge pull request #5250 from alphagov/is-supported-export
Browse files Browse the repository at this point in the history
Add `isSupported` to `all.mjs`
  • Loading branch information
patrickpatrickpatrick authored Aug 19, 2024
2 parents e944196 + 9af37d9 commit f6c4859
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/govuk-frontend/src/govuk/all.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion packages/govuk-frontend/src/govuk/all.puppeteer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions packages/govuk-frontend/src/govuk/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<body>` checked for browser support
* @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support
* @returns {boolean} Whether GOV.UK Frontend is supported on this page
*/
export function isSupported($scope = document.body) {
Expand Down

0 comments on commit f6c4859

Please sign in to comment.