-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
116 lines (94 loc) · 2.52 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
const Stack = require('.')
const test = require('tape')
const Value = require('mutant/value')
const watch = require('mutant/watch')
test('sync renderKV', t => {
const _kv = {}, _ctx = {}, el = {}
t.plan(3)
const stack = Stack().use( (kv, ctx) => {
t.equals(kv, _kv, 'is original kv')
t.notOk(ctx.readyObs, 'called without readyObs')
return el
})
t.equal(stack.renderKV(_kv, _ctx), el)
})
test('sync renderer, renderKV called with cb', t => {
const _kv = {}, _ctx = {}, el = {}
t.plan(5)
const stack = Stack().use( (kv, ctx) => {
t.equals(kv, _kv, 'is original kv')
t.ok(ctx.readyObs, 'called with readyObs')
return el
})
t.equal(stack.renderKV(_kv, _ctx, (err, _el) => {
t.error(err)
t.equals(_el, el)
}), el)
})
test('sync renderer, renderKV called with readyObs', t => {
const _kv = {}, _ctx = {
readyObs: Value(true)
}, el = {}
t.plan(3)
const release = watch(_ctx.readyObs, ready => {
if (!ready) t.fail('readyObs should not change')
})
const stack = Stack().use( (kv, ctx) => {
t.equals(kv, _kv, 'is original kv')
t.ok(ctx.readyObs, 'called with readyObs')
return el
})
t.equal(stack.renderKV(_kv, _ctx), el)
release()
})
test('async renderer, renderKV called with readyObs', t => {
const _kv = {}, _ctx = {
readyObs: Value(true)
}, el = {}
const stack = Stack().use( (kv, ctx) => {
t.equals(kv, _kv, 'is original kv')
t.ok(ctx.readyObs, 'called with readyObs')
ctx.readyObs.set(false)
setTimeout( ()=> {
el.done = true
ctx.readyObs.set(true)
}, 20)
return el
})
let release
release = watch(_ctx.readyObs, ready => {
if (!release || !ready) return
t.ok(el.done)
release()
t.end()
})
t.equal(stack.renderKV(_kv, _ctx), el)
})
test.skip('renderSingle (key, sync renderer, cb)', t => {
const _kv = {
key: "%eMe2hfQ+gI4NKQJzoycSQmefvSLKkwmdXBGj6JRQHwM=.sha256",
value: 'bar'
}, _ctx = {}, _el = {}
t.plan(7)
const ssb = {
revisions: {
get: (key, cb) => {
t.equal(key, _kv.key)
setTimeout( ()=>{
cb(null, _kv.value)
}, 20)
}
}
}
const stack = Stack(ssb).use( (kv, ctx) => {
t.deepEqual(kv, _kv)
t.ok(ctx.readyObs, 'ctx has readyObs')
return _el
})
const el = stack.renderSingle(_kv.key, (err, el) => {
t.error(err, 'no error')
t.equal(el, _el, 'callback called with non-observable')
})
t.ok(typeof el == 'function', 'el is observable')
t.deepEqual(el(), [], 'that resolves to []')
})