diff --git a/packages/govuk-frontend/src/govuk/components/tag/template.jsdom.test.js b/packages/govuk-frontend/src/govuk/components/tag/template.jsdom.test.js new file mode 100644 index 0000000000..015e989b5b --- /dev/null +++ b/packages/govuk-frontend/src/govuk/components/tag/template.jsdom.test.js @@ -0,0 +1,52 @@ +const { getExamples, render } = require('@govuk-frontend/lib/components') + +describe('Tag', () => { + let examples + + beforeAll(async () => { + examples = await getExamples('tag') + }) + + it('outputs a element', () => { + document.body.innerHTML = render('tag', examples.default) + const $component = document.querySelector('.govuk-tag') + + expect($component.tagName).toBe('STRONG') + }) + + it('contains the content from the `text` option', () => { + document.body.innerHTML = render('tag', examples.default) + const $component = document.querySelector('.govuk-tag') + + expect($component).toHaveTextContent('Alpha') + }) + + it('includes additional classes from the `classes` option', () => { + document.body.innerHTML = render('tag', examples.grey) + const $component = document.querySelector('.govuk-tag') + + expect($component).toHaveClass('govuk-tag--grey') + }) + + it('escapes HTML when using the `text` option', () => { + document.body.innerHTML = render('tag', examples['html as text']) + const $component = document.querySelector('.govuk-tag') + + expect($component).toHaveTextContent('Alpha') + }) + + it('does not escape HTML when using the `html` option', () => { + document.body.innerHTML = render('tag', examples.html) + const $component = document.querySelector('.govuk-tag') + + expect($component).toContainHTML('Alpha') + }) + + it('sets any additional attributes based on the `attributes` option', () => { + document.body.innerHTML = render('tag', examples.attributes) + const $component = document.querySelector('.govuk-tag') + + expect($component).toHaveAttribute('data-test', 'attribute') + expect($component).toHaveAttribute('id', 'my-tag') + }) +}) diff --git a/packages/govuk-frontend/src/govuk/components/tag/template.test.js b/packages/govuk-frontend/src/govuk/components/tag/template.test.js deleted file mode 100644 index aeec33ad19..0000000000 --- a/packages/govuk-frontend/src/govuk/components/tag/template.test.js +++ /dev/null @@ -1,60 +0,0 @@ -const { render } = require('@govuk-frontend/helpers/nunjucks') -const { getExamples } = require('@govuk-frontend/lib/components') - -describe('Tag', () => { - let examples - - beforeAll(async () => { - examples = await getExamples('tag') - }) - - describe('default example', () => { - it('renders the default example with strong element and text', () => { - const $ = render('tag', examples.default) - - const $component = $('.govuk-tag') - expect($component.get(0).tagName).toBe('strong') - expect($component.text()).toContain('Alpha') - }) - - it('renders classes', () => { - const $ = render('tag', examples.grey) - - const $component = $('.govuk-tag') - expect($component.hasClass('govuk-tag--grey')).toBeTruthy() - }) - }) - - describe('custom options', () => { - it('renders custom text', () => { - const $ = render('tag', examples.grey) - - const $component = $('.govuk-tag') - expect($component.html()).toContain('Grey') - }) - - it('renders attributes', () => { - const $ = render('tag', examples.attributes) - - const $component = $('.govuk-tag') - expect($component.attr('data-test')).toBe('attribute') - expect($component.attr('id')).toBe('my-tag') - }) - }) - - describe('html', () => { - it('renders escaped html when passed to text', () => { - const $ = render('tag', examples['html as text']) - - const $component = $('.govuk-tag') - expect($component.html()).toContain('<span>Alpha</span>') - }) - - it('renders html', () => { - const $ = render('tag', examples.html) - - const $component = $('.govuk-tag') - expect($component.html()).toContain('Alpha') - }) - }) -})