-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
57 lines (41 loc) · 1.59 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// test suite for the xml element string function
'use strict'
var expect = require('chai').expect
var element = require('./')
describe('xml element string function', function() {
it('should be able to create a node', function() {
var result = element('node')
var expected = '<node/>'
expect(result).to.equal(expected)
})
it('should be able to create a node with attributes', function() {
var result = element('foo', {bar: 'baz', quux: 'hello'})
var expected = '<foo bar="baz" quux="hello"/>'
expect(result).to.equal(expected)
})
it('should not write null attributes', function() {
var result = element('foo', {bar: undefined, baz: 'quux', nope: null})
var expected = '<foo baz="quux"/>'
expect(result).to.equal(expected)
})
it('should escape html characters in the tag', function() {
var result = element('foo/>danger')
var expected = '<foo/>danger/>'
expect(result).to.equal(expected)
})
it('should escape html characters in the attribute names', function() {
var result = element('foo', {'/>danger': 'bar'})
var expected = '<foo />danger="bar"/>'
expect(result).to.equal(expected)
})
it('should escape html characters in the attribute values', function() {
var result = element('foo', {bar: '"/>danger'})
var expected = '<foo bar=""/>danger"/>'
expect(result).to.equal(expected)
})
it('should handle an array of children', function() {
var result = element('node', {}, ['<child/>', '<child/>'])
var expected = '<node><child/><child/></node>'
expect(result).to.equal(expected)
})
})