Skip to content

Commit

Permalink
Merge pull request #1869 from alphagov/change-module-scope
Browse files Browse the repository at this point in the history
Change GOVUK Modules scope to document
  • Loading branch information
DilwoarH committed Jan 14, 2021
2 parents 19cd9a8 + ea6d87b commit ab2be44
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Tidy component filenames ([PR #1848](https://github.com/alphagov/govuk_publishing_components/pull/1848))
* Add print styling for magna charta component ([PR #1867](https://github.com/alphagov/govuk_publishing_components/pull/1867))
* Add custom aria label option for layout header nav ([PR #1865](https://github.com/alphagov/govuk_publishing_components/pull/1865))
* Change GOVUK Modules scope to document ([PR #1869](https://github.com/alphagov/govuk_publishing_components/pull/1869))

## 23.12.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

GOVUK.modules = {
find: function (container) {
container = container || $('body')
container = container || $(document)

var modules
var moduleSelector = '[data-module]'
Expand Down
25 changes: 24 additions & 1 deletion spec/javascripts/govuk_publishing_components/modules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('GOVUK Modules', function () {
'use strict'
var GOVUK = window.GOVUK

it('finds modules', function () {
it('finds modules in body', function () {
var module = $('<div data-module="a-module"></div>')
$('body').append(module)

Expand All @@ -15,6 +15,29 @@ describe('GOVUK Modules', function () {
module.remove()
})

it('finds modules in head', function () {
var module = $('<meta name="fake-meta" content="blah" data-module="a-module">')
$('head').append(module)

expect(GOVUK.modules.find().length).toBe(1)
expect(GOVUK.modules.find().eq(0).is('[data-module="a-module"]')).toBe(true)
module.remove()
})

it('finds modules in a page', function () {
var headModule = $('<meta name="fake-meta" content="blah" data-module="head-module">')
$('head').append(headModule)

var bodyModule = $('<div data-module="body-module"></div>')
$('body').append(bodyModule)

expect(GOVUK.modules.find().length).toBe(2)
expect(GOVUK.modules.find().eq(0).is('[data-module="head-module"]')).toBe(true)
expect(GOVUK.modules.find().eq(1).is('[data-module="body-module"]')).toBe(true)
headModule.remove()
bodyModule.remove()
})

it('finds modules in a container', function () {
var module = $('<div data-module="a-module"></div>')
var container = $('<div></div>').append(module)
Expand Down

0 comments on commit ab2be44

Please sign in to comment.