-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
60 lines (48 loc) · 1.43 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
const vdom = require('virtual-dom')
const h = require('virtual-dom/h')
const test = require('tape')
const raf = require('raf')
global.window = {}
function render (state) {
return h('div', [state.text])
}
const vraf = require('./')
test('vraf() should return a tree', function (t) {
t.plan(1)
const tree = vraf({}, render, vdom)
t.equal(typeof tree, 'object')
})
test('.render() should render to a dom node', function (t) {
t.plan(2)
const state = { text: 'hello world' }
const tree = vraf(state, render, vdom)
const node = tree.render()
t.equal(typeof node, 'object')
t.equal(node.childNodes[0].data, 'hello world')
})
test('.update() should update values', function (t) {
t.plan(4)
const state = { text: 'hello world' }
const tree = vraf(state, render, vdom)
const node = tree.render()
t.equal(typeof node, 'object')
t.equal(node.childNodes[0].data, 'hello world')
tree.update({ text: 'beep boop' })
raf(function () {
t.equal(typeof node, 'object')
t.equal(node.childNodes[0].data, 'beep boop')
})
})
test('.update() should do nothing if no data is passed', function (t) {
t.plan(4)
const state = { text: 'hello world' }
const tree = vraf(state, render, vdom)
const node = tree.render()
t.equal(typeof node, 'object')
t.equal(node.childNodes[0].data, 'hello world')
tree.update()
raf(function () {
t.equal(typeof node, 'object')
t.equal(node.childNodes[0].data, 'hello world')
})
})