Skip to content
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

Update hint template tests to use jsdom #5050

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { getExamples, render } = require('@govuk-frontend/lib/components')

describe('Hint', () => {
let examples

beforeAll(async () => {
examples = await getExamples('hint')
})

it('contains the hint text', () => {
document.body.innerHTML = render('hint', examples.default)

const $component = document.querySelector('.govuk-hint')
expect($component).toHaveTextContent(
"It's on your National Insurance card, benefit letter, payslip or P60. For example, 'QQ 12 34 56 C'."
)
})

it('includes additional classes from the `classes` option', () => {
document.body.innerHTML = render('hint', examples.classes)

const $component = document.querySelector('.govuk-hint')
expect($component).toHaveClass('app-hint--custom-modifier')
})

it('does not include an `id` attribute if the `id` option is not set', () => {
document.body.innerHTML = render('hint', examples.default)

const $component = document.querySelector('.govuk-hint')
expect($component).not.toHaveAttribute('id')
})

it('sets the `id` attribute based on the `id` option', () => {
document.body.innerHTML = render('hint', examples.id)

const $component = document.querySelector('.govuk-hint')
expect($component).toHaveAttribute('id', 'my-hint')
})

it('escapes HTML when using the `text` option', () => {
document.body.innerHTML = render('hint', examples['html as text'])

const $component = document.querySelector('.govuk-hint')
expect($component).toHaveTextContent(
'Unexpected <strong>bold text</strong> in body'
)
})

it('does not escape HTML when using the `html` option', () => {
document.body.innerHTML = render('hint', examples['with html'])

const $component = document.querySelector('.govuk-hint')
expect($component).toContainHTML(
'It\'s on your National Insurance card, benefit letter, payslip or <a class="govuk-link" href="#">P60</a>.\n For example, \'QQ 12 34 56 C\'.'
)
})

it('sets any additional attributes based on the `attributes` option', () => {
document.body.innerHTML = render('hint', examples.attributes)

const $component = document.querySelector('.govuk-hint')
expect($component).toHaveAttribute('data-attribute', 'my data value')
})
})
68 changes: 0 additions & 68 deletions packages/govuk-frontend/src/govuk/components/hint/template.test.js

This file was deleted.