20 lines
777 B
JavaScript
20 lines
777 B
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { interpolate, renderReportHtml, renderEmailHtml } from './templateEngine.js'
|
|
|
|
test('interpolates nested values', () => {
|
|
assert.equal(interpolate('Hello {{customer.name}}', { customer: { name: 'Kauri' } }), 'Hello Kauri')
|
|
})
|
|
|
|
test('report output escapes injected markup', () => {
|
|
const html = renderReportHtml({ blocks: [{ type: 'text', props: { text: '{{value}}' } }] }, { value: '<script>x</script>' })
|
|
assert.match(html, /<script>/)
|
|
assert.doesNotMatch(html, /<script>x/)
|
|
})
|
|
|
|
test('email renderer produces HTML', () => {
|
|
const html = renderEmailHtml({ blocks: [{ type: 'heading', props: { text: 'Hello' } }] }, {})
|
|
assert.match(html, /Hello/)
|
|
assert.match(html, /doctype/i)
|
|
})
|