Skip to content

Commit

Permalink
Add test for values passed via safe filter
Browse files Browse the repository at this point in the history
  • Loading branch information
querkmachine committed Apr 18, 2024
1 parent 4e473eb commit fe7a019
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/govuk-frontend/src/govuk/macros/attributes.unit.test.mjs
@@ -1,4 +1,5 @@
import { renderMacro } from '@govuk-frontend/lib/components'
import nunjucks from 'nunjucks'

describe('attributes.njk', () => {
describe('govukAttributes', () => {
Expand Down Expand Up @@ -262,5 +263,23 @@ describe('attributes.njk', () => {

expect(attributes).toBe('')
})

it('outputs values that are passed from the `safe` filter', () => {
// Set up a tiny Nunjucks environment, just so we can get the native `safe` filter
const nunjucksEnv = nunjucks.configure([])

const attributes = renderMacro(
'govukAttributes',
'govuk/macros/attributes.njk',
{
context: {
'data-text': 'Testing',
'data-safe-text': nunjucksEnv.getFilter('safe')('Testing')
}
}
)

expect(attributes).toBe(' data-text="Testing" data-safe-text="Testing"')
})
})
})

0 comments on commit fe7a019

Please sign in to comment.