Skip to content

Commit 9bc5e9b

Browse files
Moshood AlabidunMoshood Alabidun
authored andcommitted
Custom-Html-Test
1 parent ccf8299 commit 9bc5e9b

5 files changed

Lines changed: 9 additions & 9 deletions

File tree

packages/govuk-frontend/src/govuk/components/components.template.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ describe('Components', () => {
6969
context: fixture.options,
7070
fixture
7171
})}
72-
73-
<!--
74-
Target for references in examples (e.g. aria-controls)
75-
https://html-validate.org/rules/no-missing-references.html
76-
-->
77-
<div id="test-target-element"></div>
72+
${fixture.supportingHTML ?? ''}
7873
`
7974

8075
// Validate HTML

packages/govuk-frontend/src/govuk/components/label/label.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ examples:
9494
- name: for
9595
hidden: true
9696
options:
97-
for: test-target-element
97+
for: test-target-input
9898
text: National Insurance number
99+
supportingHTML: '<input type="text" id="test-target-input">'
99100
- name: attributes
100101
hidden: true
101102
options:

packages/govuk-frontend/src/govuk/components/label/template.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Label', () => {
5858
const $ = render('label', examples.for)
5959

6060
const labelForAttr = $('.govuk-label').attr('for')
61-
expect(labelForAttr).toBe('test-target-element')
61+
expect(labelForAttr).toBe('test-target-input')
6262
})
6363

6464
it('can be nested inside an H1 using isPageHeading', () => {

shared/lib/components.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ module.exports = {
324324
* @property {boolean} [screenshot] - Screenshot and include in visual regression tests
325325
* @property {PageTemplateOptions} [pageTemplateOptions] - Page template options for render
326326
* @property {MacroOptions} options - Nunjucks macro options (or params)
327+
* @property {string} [supportingHTML] - Supporting HTML to inject during tests (e.g., target elements for aria-controls, label for attributes)
327328
*/
328329

329330
/**

shared/tasks/components.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ async function generateFixture(componentDataPath, options) {
130130
screenshot: example.screenshot ?? false,
131131

132132
// Add rendered Nunjucks example to fixture
133-
html: html.trim()
133+
html: html.trim(),
134+
135+
// Add supporting HTML for tests (e.g., target elements for aria-controls, label for attributes)
136+
supportingHTML: example.supportingHTML ?? ''
134137
}
135138
}
136139
)

0 commit comments

Comments
 (0)