Files
shields/badge-maker/lib/xml.spec.js
Paul Melnikow cdd68fee7f Make for-the-badge letter spacing more predictable, and rewrite layout logic (#5754)
* Rewrite for-the-badge renderer
* Update snapshots
* Remove pixel grid alignment in for-the-badge
* abstract XML stringification to XmlElement class

Co-authored-by: chris48s <chris48s@users.noreply.github.com>
Co-authored-by: chris48s <chris.shaw480@gmail.com>
2021-05-26 20:55:28 +01:00

51 lines
1.2 KiB
JavaScript

'use strict'
const { test, given } = require('sazerac')
const { XmlElement } = require('./xml')
function testRender(params) {
return new XmlElement(params).render()
}
describe('XmlElement class', function () {
test(testRender, () => {
given({ name: 'tag' }).expect('<tag/>')
given({ name: 'tag', content: ['text'] }).expect('<tag>text</tag>')
given({
name: 'tag',
content: ['not xml>>>', 'text', new XmlElement({ name: 'xml' })],
}).expect('<tag>not xml&gt;&gt;&gt; text <xml/></tag>')
given({
name: 'nested1',
content: [
new XmlElement({
name: 'nested2',
content: [new XmlElement({ name: 'nested3' })],
}),
],
}).expect('<nested1><nested2><nested3/></nested2></nested1>')
given({
name: 'tag',
attrs: {
int: 47,
text: 'text',
escape: '<escape me>',
},
}).expect('<tag int="47" text="text" escape="&lt;escape me&gt;"/>')
given({
name: 'tag',
content: ['text'],
attrs: {
int: 47,
text: 'text',
escape: '<escape me>',
},
}).expect('<tag int="47" text="text" escape="&lt;escape me&gt;">text</tag>')
})
})