Skip to content

Commit

Permalink
Fix toggle specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-kirwan authored and MartinJJones committed Apr 15, 2024
1 parent 267ad78 commit e6e1c41
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions spec/javascripts/components/metadata-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('The metadata component', function () {

function init (element, target) {
new GOVUK.Modules.Metadata(element).init()
var toggle = new GOVUK.Modules.GemToggle($(target)[0])
target && toggle.init()
/* eslint-disable no-new */
target && new GOVUK.Modules.GemToggle($(target)[0])
}
})
10 changes: 5 additions & 5 deletions spec/javascripts/components/toggle-input-class-on-focus-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe('A toggle class module', function () {
'use strict'

var element, toggle
var element

afterEach(function () {
element.remove()
Expand All @@ -17,8 +17,8 @@ describe('A toggle class module', function () {
'<input type="search" class="js-class-toggle"/>' +
'</div>')
$('body').append(element)
toggle = new GOVUK.Modules.GemToggleInputClassOnFocus(element[0])
toggle.init()
/* eslint-disable no-new */
new GOVUK.Modules.GemToggleInputClassOnFocus(element[0])
})

it('applies the focus style on focus and removes it on blur', function () {
Expand All @@ -38,8 +38,8 @@ describe('A toggle class module', function () {
'<input type="search" value="My search query" class="js-class-toggle">' +
'</div>')
$('body').append(element)
toggle = new GOVUK.Modules.GemToggleInputClassOnFocus(element[0])
toggle.init()
/* eslint-disable no-new */
new GOVUK.Modules.GemToggleInputClassOnFocus(element[0])
})

it('applies the focus style on load if the search box already has a value', function () {
Expand Down
20 changes: 10 additions & 10 deletions spec/javascripts/components/toggle-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('A toggle module', function () {
'<div id="target">Target</div>' +
'</div>'
element = $(html)
var toggle = new GOVUK.Modules.GemToggle(element[0])
toggle.init()
/* eslint-disable no-new */
new GOVUK.Modules.GemToggle(element[0])
})

it('adds aria attributes to toggles', function () {
Expand All @@ -42,8 +42,8 @@ describe('A toggle module', function () {
'<div id="target" class="js-hidden">Target</div>' +
'</div>'
element = $(html)
var toggle = new GOVUK.Modules.GemToggle(element[0])
toggle.init()
/* eslint-disable no-new */
new GOVUK.Modules.GemToggle(element[0])
element.find('.my-toggle')[0].click()
})

Expand Down Expand Up @@ -83,8 +83,8 @@ describe('A toggle module', function () {
'<div id="target" class="js-hidden">Target</div>' +
'</div>'
element = $(html)
var toggle = new GOVUK.Modules.GemToggle(element[0])
toggle.init()
/* eslint-disable no-new */
new GOVUK.Modules.GemToggle(element[0])
element.find('.my-toggle')[0].click()
})

Expand Down Expand Up @@ -131,8 +131,8 @@ describe('A toggle module', function () {
'<div id="another-target" class="js-hidden">Another target</div>' +
'</div>'
element = $(html)
var toggle = new GOVUK.Modules.GemToggle(element[0])
toggle.init()
/* eslint-disable no-new */
new GOVUK.Modules.GemToggle(element[0])

expect(element.find('#target').is('.js-hidden')).toBe(true)
expect(element.find('#another-target').is('.js-hidden')).toBe(true)
Expand All @@ -155,8 +155,8 @@ describe('A toggle module', function () {
'<div id="target">Target</div>' +
'</div>'
element = $(html)
var toggle = new GOVUK.Modules.GemToggle(element[0])
toggle.init()
/* eslint-disable no-new */
new GOVUK.Modules.GemToggle(element[0])

expect(element.find('#target').is('.myclass')).toBe(false)
element.find('.my-toggle')[0].click()
Expand Down

0 comments on commit e6e1c41

Please sign in to comment.