diff --git a/spec/javascripts/components/accordion-spec.js b/spec/javascripts/components/accordion-spec.js index 35a0776672..a975f53108 100644 --- a/spec/javascripts/components/accordion-spec.js +++ b/spec/javascripts/components/accordion-spec.js @@ -48,7 +48,8 @@ describe('Accordion component', function () { '' function startAccordion () { - new GOVUK.Modules.GemAccordion(accordion).init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemAccordion(accordion) } beforeEach(function () { diff --git a/spec/javascripts/components/checkboxes-spec.js b/spec/javascripts/components/checkboxes-spec.js index ec2f15557d..343a6d368a 100644 --- a/spec/javascripts/components/checkboxes-spec.js +++ b/spec/javascripts/components/checkboxes-spec.js @@ -3,7 +3,8 @@ describe('Checkboxes component', function () { function loadCheckboxesComponent () { - new GOVUK.Modules.GemCheckboxes($('.gem-c-checkboxes')[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.GemCheckboxes($('.gem-c-checkboxes')[0]) } var FIXTURE = diff --git a/spec/javascripts/components/contextual-guidance-spec.js b/spec/javascripts/components/contextual-guidance-spec.js index 7fa7882ade..3ca7a8ade1 100644 --- a/spec/javascripts/components/contextual-guidance-spec.js +++ b/spec/javascripts/components/contextual-guidance-spec.js @@ -35,8 +35,10 @@ describe('Contextual guidance component', function () { document.body.appendChild(container) var titleContextualGuidance = document.getElementById('document-title-guidance') var summaryContextualGuidance = document.getElementById('document-summary-guidance') - new GOVUK.Modules.ContextualGuidance(titleContextualGuidance).init() - new GOVUK.Modules.ContextualGuidance(summaryContextualGuidance).init() + /* eslint-disable no-new */ + new GOVUK.Modules.ContextualGuidance(titleContextualGuidance) + /* eslint-disable no-new */ + new GOVUK.Modules.ContextualGuidance(summaryContextualGuidance) }) afterEach(function () { diff --git a/spec/javascripts/components/cookie-banner-spec.js b/spec/javascripts/components/cookie-banner-spec.js index 75c98b9499..ee38b2bd6c 100644 --- a/spec/javascripts/components/cookie-banner-spec.js +++ b/spec/javascripts/components/cookie-banner-spec.js @@ -57,7 +57,8 @@ describe('Cookie banner', function () { it('should show the cookie banner', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var cookieBannerMain = document.querySelector('.js-banner-wrapper') var cookieBannerConfirmationAccept = document.querySelector('.gem-c-cookie-banner__confirmation-message--accepted') @@ -73,7 +74,8 @@ describe('Cookie banner', function () { GOVUK.setDefaultConsentCookie() // Set default cookies, which are set whether there is any interaction or not. var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var cookieBannerMain = document.querySelector('.js-banner-wrapper') var cookieBannerConfirmationAccept = document.querySelector('.gem-c-cookie-banner__confirmation-message--accepted') @@ -89,14 +91,16 @@ describe('Cookie banner', function () { GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 }) var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(element).toBeHidden() }) it('sets a default consent cookie', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(GOVUK.getCookie('cookies_preferences_set')).toEqual(null) expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) @@ -107,7 +111,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'deleteUnconsentedCookies').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) expect(GOVUK.deleteUnconsentedCookies).toHaveBeenCalled() @@ -119,7 +124,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) // Manually reset the consent cookie so we can check the accept button works as intended expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) @@ -144,7 +150,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) // Manually reset the consent cookie so we can check the accept button works as intended expect(GOVUK.getCookie('cookies_policy')).toEqual(DEFAULT_COOKIE_CONSENT) @@ -161,7 +168,8 @@ describe('Cookie banner', function () { it('shows a confirmation message when cookies have been accepted', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var acceptCookiesButton = document.querySelector('[data-accept-cookies]') var confirmationMessageAccepted = document.querySelector('.gem-c-cookie-banner__confirmation-message--accepted') @@ -176,7 +184,8 @@ describe('Cookie banner', function () { it('shows a confirmation message when cookies have been rejected', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var rejectCookiesButton = document.querySelector('[data-reject-cookies]') var confirmationMessageRejected = document.querySelector('.gem-c-cookie-banner__confirmation-message--rejected') @@ -191,7 +200,8 @@ describe('Cookie banner', function () { it('set focus to the confirmation message after clicking button', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var rejectCookiesButton = document.querySelector('[data-reject-cookies]') var confirmationMessage = document.querySelector('.gem-c-cookie-banner__confirmation') @@ -206,7 +216,8 @@ describe('Cookie banner', function () { it('set cookies_preferences_set cookie, and re-set cookies_policy expiration date when rejecting cookies', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var rejectCookiesButton = document.querySelector('[data-reject-cookies]') @@ -220,7 +231,8 @@ describe('Cookie banner', function () { spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) var link = document.querySelector('button[data-hide-cookie-banner="true"]') link.dispatchEvent(new window.Event('click')) @@ -243,7 +255,8 @@ describe('Cookie banner', function () { it('should hide the cookie banner', function () { var element = document.querySelector('[data-module="cookie-banner"]') - new GOVUK.Modules.CookieBanner(element).init() + /* eslint-disable no-new */ + new GOVUK.Modules.CookieBanner(element) expect(element).toBeHidden() }) }) diff --git a/spec/javascripts/components/feedback-spec.js b/spec/javascripts/components/feedback-spec.js index 37a984c148..13c31e3a8e 100644 --- a/spec/javascripts/components/feedback-spec.js +++ b/spec/javascripts/components/feedback-spec.js @@ -780,7 +780,8 @@ describe('Feedback component', function () { }) function loadFeedbackComponent () { - new GOVUK.Modules.Feedback($('.gem-c-feedback')[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Feedback($('.gem-c-feedback')[0]) } function fillAndSubmitSomethingIsWrongForm () { diff --git a/spec/javascripts/components/govspeak-spec.js b/spec/javascripts/components/govspeak-spec.js index 5de65f4f27..eb6aa445dc 100644 --- a/spec/javascripts/components/govspeak-spec.js +++ b/spec/javascripts/components/govspeak-spec.js @@ -18,6 +18,7 @@ describe('Govspeak', function () { document.body.appendChild(container) var element = document.querySelector('[data-module="govspeak"]') + /* eslint-disable no-new */ new GOVUK.Modules.Govspeak(element).init() expect(document.querySelectorAll('.gem-c-govspeak__youtube-video').length).toBe(1) @@ -32,6 +33,7 @@ describe('Govspeak', function () { document.body.appendChild(container) var element = document.querySelector('[data-module="govspeak"]') + /* eslint-disable no-new */ new GOVUK.Modules.Govspeak(element).init() expect(document.querySelectorAll('.gem-c-govspeak__youtube-video').length).toBe(0) @@ -54,6 +56,7 @@ describe('Govspeak', function () { document.body.appendChild(container) var element = document.querySelector('[data-module="govspeak"]') + /* eslint-disable no-new */ new GOVUK.Modules.Govspeak(element).init() expect(document.querySelectorAll('.mc-chart').length).toBe(1) diff --git a/spec/javascripts/components/intervention-spec.js b/spec/javascripts/components/intervention-spec.js index 2b59a525ff..a455733ac5 100644 --- a/spec/javascripts/components/intervention-spec.js +++ b/spec/javascripts/components/intervention-spec.js @@ -61,6 +61,7 @@ describe('Intervention banner component', function () { it('does not display the banner', function () { GOVUK.setCookie('intervention_campaign', 'test-intervention-name', { days: 1 }) var element = document.querySelector('[data-module="intervention"]') + /* eslint-disable no-new */ new GOVUK.Modules.Intervention(element).init() var banner = document.querySelector('.gem-c-intervention') diff --git a/spec/javascripts/components/layout-super-navigation-header-spec.js b/spec/javascripts/components/layout-super-navigation-header-spec.js index 33a8ddf516..d539a33141 100644 --- a/spec/javascripts/components/layout-super-navigation-header-spec.js +++ b/spec/javascripts/components/layout-super-navigation-header-spec.js @@ -5,7 +5,6 @@ describe('The super header navigation', function () { 'use strict' var container - var thisModule beforeEach(function () { container = document.createElement('div') @@ -198,10 +197,6 @@ describe('The super header navigation', function () { '' document.body.appendChild(container) - - var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') - thisModule = new GOVUK.Modules.SuperNavigationMegaMenu($element) - spyOn(GOVUK.analytics, 'trackEvent') }) @@ -215,7 +210,9 @@ describe('The super header navigation', function () { describe('on both small and large screens', function () { beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) }) it('has the initialised class once the JavaScript has run', function () { @@ -229,7 +226,9 @@ describe('The super header navigation', function () { var $button beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) $button = document.querySelector('#super-navigation-menu-toggle') }) @@ -347,7 +346,9 @@ describe('The super header navigation', function () { var $button beforeEach(function () { - thisModule.init() + var $element = document.querySelector('[data-module="super-navigation-mega-menu"]') + /* eslint-disable no-new */ + new GOVUK.Modules.SuperNavigationMegaMenu($element) $button = document.querySelector('#super-search-menu-toggle') }) diff --git a/spec/javascripts/components/option-select-spec.js b/spec/javascripts/components/option-select-spec.js index 6d3b6b98d0..36fcc32118 100644 --- a/spec/javascripts/components/option-select-spec.js +++ b/spec/javascripts/components/option-select-spec.js @@ -104,7 +104,11 @@ describe('An option select component', function () { var $closedOnLoadFixture = $(optionSelectWithAttrs('data-closed-on-load=true')) $('body').append($closedOnLoadFixture) - new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0]).init() + console.log($closedOnLoadFixture[0].outerHTML) + + console.log(new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0])) + + console.log($closedOnLoadFixture[0].outerHTML) expect($closedOnLoadFixture.find('button').attr('aria-expanded')).toBe('false') }) @@ -113,7 +117,8 @@ describe('An option select component', function () { var $openOnLoadFixture = $(optionSelectWithAttrs('data-closed-on-load=false')) $('body').append($openOnLoadFixture) - new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]) expect($openOnLoadFixture.find('button').attr('aria-expanded')).toBe('true') expect($('body').find('.js-options-container').is(':visible')).toBe(true) @@ -123,7 +128,8 @@ describe('An option select component', function () { var $openOnLoadFixture = $(optionSelectWithAttrs('')) $('body').append($openOnLoadFixture) - new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($openOnLoadFixture[0]) expect($openOnLoadFixture.find('button').attr('aria-expanded')).toBe('true') expect($('body').find('.js-options-container').is(':visible')).toBe(true) @@ -132,7 +138,8 @@ describe('An option select component', function () { it('sets the height of the options container as part of initialisation', function () { $element = document.createElement('div') $element.innerHTML = html - new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) expect($($element).find('.js-options-container').attr('style')).toContain('height') }) @@ -140,7 +147,8 @@ describe('An option select component', function () { it('doesn\'t set the height of the options container as part of initialisation if closed-on-load is true', function () { var $closedOnLoadFixture = $(optionSelectWithAttrs('data-closed-on-load=true')) - new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($closedOnLoadFixture[0]) expect($closedOnLoadFixture.find('.js-options-container').attr('style')).not.toContain('height') }) @@ -148,7 +156,8 @@ describe('An option select component', function () { it('replaces the `span.gem-c-option-select__title` with a button', function () { $element = document.createElement('div') $element.innerHTML = html - new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) expect($($element).find('button')).toBeDefined() }) @@ -161,7 +170,6 @@ describe('An option select component', function () { $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) - optionSelect.init() }) it('calls optionSelect.close() if the optionSelect is currently open', function () { @@ -185,7 +193,8 @@ describe('An option select component', function () { $element.innerHTML = html $('body').append($element) - new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')).init() + /* eslint-disable no-new */ + new GOVUK.Modules.OptionSelect($element.querySelector('.gem-c-option-select')) }) it('closes and opens the option select', function () { @@ -215,7 +224,6 @@ describe('An option select component', function () { $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() optionSelect.setContainerHeight(100) firstCheckbox = optionSelect.$allCheckboxes[0] lastCheckbox = optionSelect.$allCheckboxes[optionSelect.$allCheckboxes.length - 1] @@ -237,7 +245,6 @@ describe('An option select component', function () { $element = $(html) $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() }) it('returns all the checkboxes if the container doesn\'t overflow', function () { @@ -277,7 +284,6 @@ describe('An option select component', function () { }) $checkboxListInner = $checkboxList.find(' > .js-auto-height-inner') - optionSelect.init() }) it('expands the checkbox-container to fit checkbox list if the list is < 50px larger than the container', function () { @@ -308,7 +314,6 @@ describe('An option select component', function () { $wrapper.hide() optionSelect = new GOVUK.Modules.OptionSelect($wrapper.find('.gem-c-option-select')[0]) - optionSelect.init() }) afterEach(function () { @@ -328,7 +333,6 @@ describe('An option select component', function () { var $wrapper = $('
').addClass('wrapper').hide().html($element) $('body').append($wrapper) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() }) afterEach(function () { @@ -362,7 +366,6 @@ describe('An option select component', function () { $element.find('.gem-c-checkboxes').prepend($(filterSpan)) $('body').append($element) optionSelect = new GOVUK.Modules.OptionSelect($element.find('.gem-c-option-select')[0]) - optionSelect.init() jasmine.clock().install() $filterInput = document.querySelector('[name="option-select-filter"]') diff --git a/spec/javascripts/components/show-password-spec.js b/spec/javascripts/components/show-password-spec.js index 66020b6e3f..fbf3bb290f 100644 --- a/spec/javascripts/components/show-password-spec.js +++ b/spec/javascripts/components/show-password-spec.js @@ -14,7 +14,9 @@ describe('A show password component', function () { '
' + '' ) - new GOVUK.Modules.ShowPassword(element[0]).init() + /* eslint-disable no-new */ + /* eslint-disable no-new */ + new GOVUK.Modules.ShowPassword(element[0]) }) afterEach(function () { @@ -67,7 +69,9 @@ describe('A show password component', function () { '' ) $('body').append(element) - new GOVUK.Modules.ShowPassword(element.find('.gem-c-show-password')[0]).init() + /* eslint-disable no-new */ + /* eslint-disable no-new */ + new GOVUK.Modules.ShowPassword(element.find('.gem-c-show-password')[0]) $('body').on('submit', function (e) { e.preventDefault() }) @@ -104,7 +108,9 @@ describe('A show password component', function () { '' ) $('body').append(element) - new GOVUK.Modules.ShowPassword(element.find('.gem-c-show-password')[0]).init() + /* eslint-disable no-new */ + /* eslint-disable no-new */ + new GOVUK.Modules.ShowPassword(element.find('.gem-c-show-password')[0]) $('body').on('submit', function (e) { e.preventDefault() }) @@ -137,7 +143,8 @@ describe('A show password component', function () { '' + '' ) - new GOVUK.Modules.ShowPassword(element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.ShowPassword(element[0]) }) afterEach(function () { diff --git a/spec/javascripts/components/step-by-step-nav-spec.js b/spec/javascripts/components/step-by-step-nav-spec.js index a8deff8461..d803bb838f 100644 --- a/spec/javascripts/components/step-by-step-nav-spec.js +++ b/spec/javascripts/components/step-by-step-nav-spec.js @@ -120,7 +120,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) expectedstepnavStepCount = $element.find('.gem-c-step-nav__step').length expectedstepnavContentCount = $element.find('.gem-c-step-nav__step').first().find('.js-link').length expectedstepnavLinkCount = $element.find('.gem-c-step-nav__list-item').length @@ -382,7 +383,8 @@ describe('A stepnav module', function () { $element = $(html) $element.attr('data-remember', true) $element.addClass('gem-c-step-nav--large') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -430,7 +432,8 @@ describe('A stepnav module', function () { $element.attr('data-remember', true) $element.addClass('gem-c-step-nav--large') window.sessionStorage.setItem('unique-id', '["topic-step-one","topic-step-three"]') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -469,7 +472,8 @@ describe('A stepnav module', function () { $element.attr('data-remember', true) $element.addClass('gem-c-step-nav--large') window.sessionStorage.setItem('unique-id', '["topic-step-one","topic-step-two","topic-step-three"]') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -487,7 +491,8 @@ describe('A stepnav module', function () { $element = $(html) $element.attr('data-remember', true) window.sessionStorage.setItem('unique-id', '["topic-step-one","topic-step-two","topic-step-three"]') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -512,7 +517,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.find('#topic-step-two').attr('data-show', '') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) it('shows the step it\'s supposed to', function () { @@ -533,7 +539,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.addClass('gem-c-step-nav--large') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) it('triggers a google analytics custom event when clicking on the title on a big stepnav', function () { @@ -683,7 +690,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -742,7 +750,8 @@ describe('A stepnav module', function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') window.sessionStorage.setItem('govuk-step-nav-active-link_unique-id', '3.5') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -765,7 +774,8 @@ describe('A stepnav module', function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') window.sessionStorage.setItem('govuk-step-nav-active-link_unique-id', 'definitelynotvalid') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -784,7 +794,8 @@ describe('A stepnav module', function () { $element = $(html) $element.find('.js-will-be-an-active-link').addClass('gem-c-step-nav__list-item--active') $element.find('.gem-c-step-nav__step').removeClass('gem-c-step-nav__step--active') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) afterEach(function () { @@ -802,7 +813,8 @@ describe('A stepnav module', function () { beforeEach(function () { $element = $(html) $element.removeAttr('data-id') - new GOVUK.Modules.Gemstepnav($element[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav($element[0]) }) it('triggers a google analytics custom event on show all', function () { @@ -929,7 +941,8 @@ describe('A stepnav module', function () { element.childNodes[0].setAttribute('data-module', 'gemstepnav ga4-event-tracker') element.childNodes[0].setAttribute('data-ga4-expandable', '') element.querySelector('.js-step-title').innerText = "This title's got quotation marks \" in it." - new GOVUK.Modules.Gemstepnav(element.childNodes[0]).init() + /* eslint-disable no-new */ + new GOVUK.Modules.Gemstepnav(element.childNodes[0]) }) it('adds the "Show all" JSON to the JS generated "show all steps" button', function () { diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js index e6b605bb29..c3dd165919 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.spec.js @@ -69,6 +69,7 @@ describe('Google Analytics auto tracker', function () { describe('configuring tracking without any data', function () { beforeEach(function () { element.setAttribute('data-ga4-auto', '') + /* eslint-disable no-new */ new GOVUK.Modules.Ga4AutoTracker(element).init() }) @@ -80,6 +81,7 @@ describe('Google Analytics auto tracker', function () { describe('configuring tracking with incorrect data', function () { beforeEach(function () { element.setAttribute('data-ga4-auto', 'invalid json') + /* eslint-disable no-new */ new GOVUK.Modules.Ga4AutoTracker(element).init() }) @@ -110,6 +112,7 @@ describe('Google Analytics auto tracker', function () { index_section_count: undefined } element.setAttribute('data-ga4-auto', JSON.stringify(attributes)) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4AutoTracker(element).init() }) diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js index 65e2e8ca17..9872790cd0 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.spec.js @@ -76,6 +76,7 @@ describe('Google Analytics event tracker', function () { beforeEach(function () { element.setAttribute('data-ga4-event', '') document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -89,6 +90,7 @@ describe('Google Analytics event tracker', function () { beforeEach(function () { element.setAttribute('data-ga4-event', 'invalid json') document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -114,6 +116,7 @@ describe('Google Analytics event tracker', function () { } element.setAttribute('data-ga4-event', JSON.stringify(attributes)) document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -146,6 +149,7 @@ describe('Google Analytics event tracker', function () { it('records the text of the element by default', function () { element.setAttribute('data-ga4-event', JSON.stringify(attributes)) document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() expected.event_data.text = 'text from the button' @@ -157,6 +161,7 @@ describe('Google Analytics event tracker', function () { attributes.text = 'text from the attributes' element.setAttribute('data-ga4-event', JSON.stringify(attributes)) document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() expected.event_data.text = 'text from the attributes' @@ -197,6 +202,7 @@ describe('Google Analytics event tracker', function () { 'class="clickme"' + '>' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -219,6 +225,7 @@ describe('Google Analytics event tracker', function () { element.setAttribute('data-ga4-event', JSON.stringify(attributes)) element.setAttribute('aria-expanded', 'false') document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -256,6 +263,7 @@ describe('Google Analytics event tracker', function () { '>' + '' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -295,6 +303,7 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -338,6 +347,7 @@ describe('Google Analytics event tracker', function () { 'Example' + '' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -381,6 +391,7 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -404,6 +415,7 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) @@ -430,6 +442,7 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'getPathname').and.returnValue('/hello-world') @@ -477,6 +490,7 @@ describe('Google Analytics event tracker', function () { element.appendChild(noButton) document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() window.dataLayer = [] @@ -514,6 +528,7 @@ describe('Google Analytics event tracker', function () { '' + '' document.body.appendChild(element) + /* eslint-disable no-new */ new GOVUK.Modules.Ga4EventTracker(element).init() }) diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js index 89c81fd269..074a63df2b 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.spec.js @@ -93,18 +93,21 @@ describe('GA4 smart answer results tracking', function () { describe('on page load', function () { it('should push a nullified ecommerce object to the dataLayer', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() expect(window.dataLayer[0].search_results.ecommerce).toBe(null) }) it('should get the number of results i.e. 5 results in this test case', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() expect(window.dataLayer[1].search_results.results).toBe(onPageLoadExpected.search_results.results) }) it('should get the item id for each result', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -114,6 +117,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should get the item list name for each result', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -128,6 +132,7 @@ describe('GA4 smart answer results tracking', function () { } smartAnswerResultsParentEl.removeAttribute('data-ga4-list-title') + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -137,6 +142,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should get the index for each result using the data-ga4-ecommerce-index attribute', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -152,6 +158,7 @@ describe('GA4 smart answer results tracking', function () { smartAnswerResults[i].removeAttribute('data-ga4-ecommerce-index') } + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() var smartAnswerResultItems = window.dataLayer[1].search_results.ecommerce.items @@ -193,6 +200,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should push a nullified ecommerce object to the dataLayer', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() expect(window.dataLayer[0].search_results.ecommerce).toBe(null) @@ -209,6 +217,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should push 1 search result to the dataLayer (i.e. the clicked search result)', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() smartAnswerResultToBeClicked.click() @@ -216,6 +225,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should add the event_data property to the object and set it appropriately', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() smartAnswerResultToBeClicked.click() @@ -224,6 +234,7 @@ describe('GA4 smart answer results tracking', function () { }) it('should set the remaining properties appropriately', function () { + /* eslint-disable no-new */ new GOVUK.Modules.Ga4SmartAnswerResultsTracker(smartAnswerResultsParentEl).init() smartAnswerResultToBeClicked.click() diff --git a/spec/javascripts/govuk_publishing_components/modules.spec.js b/spec/javascripts/govuk_publishing_components/modules.spec.js index 2c93ad918b..fb4dc70713 100644 --- a/spec/javascripts/govuk_publishing_components/modules.spec.js +++ b/spec/javascripts/govuk_publishing_components/modules.spec.js @@ -83,6 +83,7 @@ describe('GOVUK Modules', function () { // GOV.UK Frontend Modules function TestAlertFrontendModule (element) { this.element = element + this.init() } TestAlertFrontendModule.prototype.init = function () { callbackFrontendModule(this.element) @@ -92,6 +93,7 @@ describe('GOVUK Modules', function () { // GOV.UK Gem Frontend Modules function GemTestAlertFrontendModule (element) { this.element = element + this.init() } GemTestAlertFrontendModule.prototype.init = function () { callbackGemFrontendModule(this.element) @@ -101,6 +103,7 @@ describe('GOVUK Modules', function () { // GOV.UK Frontend Module with a GOVUK Publishing Module counterpart function TestAlertPublishingAndFrontendModule (element) { this.element = element + this.init() } TestAlertPublishingAndFrontendModule.prototype.init = function () { callbackFrontendModule(this.element) @@ -110,6 +113,7 @@ describe('GOVUK Modules', function () { // GOV.UK Frontend Module that depends on cookies to start and delays function TestCookieDependencyModule (element) { this.element = element + this.init() } TestCookieDependencyModule.prototype.init = function () { this.startModule = this.startModule.bind(this) @@ -124,6 +128,7 @@ describe('GOVUK Modules', function () { // module with a deliberate error in it function TestErrorModule (element) { this.element = element + this.init() } TestErrorModule.prototype.init = function () { throw new Error('This is a deliberate error')