-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
167 lines (133 loc) · 2.99 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const serialize = require('serialize-dom')
const createElement = require('./')
const tsml = require('tsml')
const test = require('ava')
test('tag', (t) => {
const actual = createElement('h1')
const expected = '<h1></h1>'
t.is(serialize(actual), expected)
})
test('attributes', (t) => {
const actual = createElement('h1', {
id: 'header',
class: 'big'
})
const expected = '<h1 id="header" class="big"></h1>'
t.is(serialize(actual), expected)
})
test('boolean attributes', (t) => {
const actual = createElement('input', {
type: 'checkbox',
autofocus: true,
checked: false
})
const expected = tsml`
<input type="checkbox" autofocus="autofocus">
`
t.is(serialize(actual), expected)
})
test('svg attributes', (t) => {
const node = createElement('use', {
'xlink:href': '#test'
})
t.is(node.attributes[0].ns, 'http://www.w3.org/1999/xlink')
})
test('unknown namespace attributes', (t) => {
const node = createElement('use', {
'randomnamespace:href': '#test'
})
t.is(node.attributes[0].ns, null)
})
test('children', (t) => {
const actual = createElement('div',
createElement('p'),
createElement('p')
)
const expected = tsml`
<div>
<p></p>
<p></p>
</div>
`
t.is(serialize(actual), expected)
})
test('children as a falsy value', (t) => {
const actual = createElement('div',
undefined,
null,
createElement('p', 'hello')
)
const expected = tsml`
<div>
<p>hello</p>
</div>
`
t.is(serialize(actual), expected)
})
test('children as an array', (t) => {
const actual = createElement('div', [
createElement('p'),
createElement('p')
])
const expected = tsml`
<div>
<p></p>
<p></p>
</div>
`
t.is(serialize(actual), expected)
})
test('children as an array with attributes', (t) => {
const actual = createElement('div', {
class: 'one'
}, [
createElement('p'),
createElement('p')
])
const expected = tsml`
<div class="one">
<p></p>
<p></p>
</div>
`
t.is(serialize(actual), expected)
})
test('children as a text node', (t) => {
const actual = createElement('p', 'text')
const expected = '<p>text</p>'
t.is(serialize(actual), expected)
})
test('children and attributes', (t) => {
const actual = createElement('div', { id: 'wrapper' },
createElement('p', '1'),
createElement('p', '2')
)
const expected = tsml`
<div id="wrapper">
<p>1</p>
<p>2</p>
</div>
`
t.is(serialize(actual), expected)
})
test('tags as functions', (t) => {
const { div, p } = createElement
const actual = div({ id: 'wrapper' },
p('1'),
p('2')
)
const expected = tsml`
<div id="wrapper">
<p>1</p>
<p>2</p>
</div>
`
t.is(serialize(actual), expected)
})
test.todo('svg tags as functions')
test('events', (t) => {
const handler = () => 'clicked'
const node = createElement('button', { onClick: handler })
t.is(node.onclick, handler)
t.is(node.onclick(), 'clicked')
})