forked from ungoldman/hyperaxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
129 lines (103 loc) · 2.9 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
var x = require('./')
var test = require('tape')
var tags = require('html-tags')
test('factory function signature', t => {
t.plan(5)
t.equal(typeof x, 'function', 'factory function exists')
t.equal(typeof x('p'), 'function', 'factory produces function')
var h = x('p')('hello')
t.equal(typeof h, 'object', 'tag function produces object')
t.equal(h.nodeName, 'p', 'tag object has correct nodeName')
t.equal(h.childNodes[0].value, 'hello', 'tag object has text node')
})
test('all tags', function (t) {
t.plan(tags.length)
tags.forEach(function (tag) {
t.equal(typeof x[tag], 'function', tag + ' method exists')
})
})
test('complex nested arrays', function (t) {
var h = x.div({ id: 'kidz' }, 'I ', ['am ', ['a ', [x.em('very'), ' ', ['nested ', 'bunch ']]], 'of '], x.strong('kids'), '.')
t.equal(h.outerHTML, '<div id="kidz">I am a <em>very</em> nested bunch of <strong>kids</strong>.</div>', 'the kids are alright')
t.end()
})
test('examples: HTML tags', t => {
t.plan(3)
var { a, img, video } = x
t.equal(
a({ href: '#' }, 'click').outerHTML,
'<a href="#">click</a>'
)
t.equal(
img({ src: 'cats.gif', alt: 'lolcats' }).outerHTML,
'<img src="cats.gif" alt="lolcats">'
)
t.equal(
video({ src: 'dogs.mp4', autoplay: true }).outerHTML,
'<video src="dogs.mp4" autoplay="true"></video>'
)
})
test('examples: element factory', t => {
t.plan(1)
var p = x('p')
t.equal(
p('over 9000').outerHTML,
'<p>over 9000</p>'
)
})
test('examples: css shorthand', t => {
t.plan(1)
var horse = x('.horse.with-hands')
t.equal(
horse('neigh').outerHTML,
'<div class="horse with-hands">neigh</div>'
)
})
test('examples: custom components', t => {
t.plan(1)
var siteNav = (...links) => x('nav.site')(
links.map(link =>
x('a.link')({ href: link.href }, link.text)
)
)
t.equal(
x.body(
siteNav(
{ href: '#apps', text: 'apps' },
{ href: '#games', text: 'games' }
)
).outerHTML,
'<body><nav class="site"><a class="link" href="#apps">apps</a><a class="link" href="#games">games</a></nav></body>'
)
})
test('examples: variadic', t => {
t.plan(1)
t.equal(
x('.variadic')(
x('h1')('hi'),
x('h2')('hello'),
x('h3')('hey'),
x('h4')('howdy')
).outerHTML,
'<div class="variadic"><h1>hi</h1><h2>hello</h2><h3>hey</h3><h4>howdy</h4></div>'
)
})
test('examples: arrays', t => {
t.plan(1)
var kids = [
x('p')('Once upon a time,'),
x('p')('there was a variadic function,'),
x('p')('that also accepted arrays.')
]
t.equal(
x('.arrays')(kids).outerHTML,
'<div class="arrays"><p>Once upon a time,</p><p>there was a variadic function,</p><p>that also accepted arrays.</p></div>'
)
})
test('getFactory: cached createFactory', t => {
t.plan(1)
var h = require('hyperscript')
var y = x.getFactory(h)
var z = x.getFactory(h)
t.ok(y === z)
})