-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add isSupported
to createAll
#5251
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for 3301745 |
JavaScript changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
index 9dc0b2147..69492a902 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
@@ -1106,13 +1106,13 @@ function initAll(e) {
function createAll(e, t, n = document) {
const i = n.querySelectorAll(`[data-module="${e.moduleName}"]`);
- return Array.from(i).map((n => {
+ return isSupported() ? Array.from(i).map((n => {
try {
return "defaults" in e && void 0 !== t ? new e(n, t) : new e(n)
} catch (i) {
return console.log(i), null
}
- })).filter(Boolean)
+ })).filter(Boolean) : (console.log(new SupportError), [])
}
Tabs.moduleName = "govuk-tabs";
export {
Action run for 3301745 |
Other changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/all.bundle.js b/packages/govuk-frontend/dist/govuk/all.bundle.js
index fd8a866cd..3b86ffe36 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.js
@@ -2389,6 +2389,10 @@
*/
function createAll(Component, config, $scope = document) {
const $elements = $scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
+ if (!isSupported()) {
+ console.log(new SupportError());
+ return [];
+ }
return Array.from($elements).map($element => {
try {
return 'defaults' in Component && typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.mjs b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
index 1baaac9d9..8725b363d 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
@@ -2383,6 +2383,10 @@ function initAll(config) {
*/
function createAll(Component, config, $scope = document) {
const $elements = $scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
+ if (!isSupported()) {
+ console.log(new SupportError());
+ return [];
+ }
return Array.from($elements).map($element => {
try {
return 'defaults' in Component && typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
diff --git a/packages/govuk-frontend/dist/govuk/init.mjs b/packages/govuk-frontend/dist/govuk/init.mjs
index f985eaffb..c8b4ab490 100644
--- a/packages/govuk-frontend/dist/govuk/init.mjs
+++ b/packages/govuk-frontend/dist/govuk/init.mjs
@@ -52,6 +52,10 @@ function initAll(config) {
*/
function createAll(Component, config, $scope = document) {
const $elements = $scope.querySelectorAll(`[data-module="${Component.moduleName}"]`);
+ if (!isSupported()) {
+ console.log(new SupportError());
+ return [];
+ }
return Array.from($elements).map($element => {
try {
return 'defaults' in Component && typeof config !== 'undefined' ? new Component($element, config) : new Component($element);
Action run for 3301745 |
@patrickpatrickpatrick I've change the base of the PR to not point to main, so we can work on the JS API without disturbing the Navigation component release. |
beforeEach(() => { | ||
document.body.classList.add('govuk-frontend-supported') | ||
}) | ||
|
||
afterEach(() => { | ||
document.body.innerHTML = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion As JSDOM doesn't get cleaned between the same tests of a given file we should ensure the class gets removed as well.
document.body.innerHTML = '' | |
document.body.outerHTML = '<body></body>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all neat, I'd just suggest a little more safety in the tests cleanup now we add a class before each of the createAll
tests.
- createAll returns empty array and throws error is `isSupported` false - update existing createAll tests and add test for `isSupported` false
c594c86
to
3301745
Compare
What
createAll
returns empty array and throws error isisSupported
falsecreateAll
tests and add test forisSupported
falseWhy
Prevents
createAll
running ifgovuk-frontend
not supported.Fixes #5213