/
test.js
57 lines (48 loc) · 1.38 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
'use strict'
var test = require('tape')
var document = require('global/document')
var raf = require('raf')
var thermo = require('./')
var Component = require('./component')
test(function (t) {
t.plan(6)
thermo.createComponent(Component, function (state, element, done) {
t.deepEqual(state(), {heading: 'Hello World!'})
t.equal(element.tagName, 'H1')
t.equal(elements().length, 1)
t.equal(elements()[0], element)
state.set({heading: 'New Heading'})
raf(function afterRender () {
t.equal(element.childNodes[0].data, 'New Heading')
done()
t.notOk(elements().length)
})
})
})
test('partial application', function (t) {
t.plan(2)
var render = thermo.createComponent(Component)
render(function (state, element, done) {
t.equal(typeof state, 'function')
t.equal(element.tagName, 'H1')
done()
})
})
test('initial state', function (t) {
t.plan(1)
var render = thermo.createComponent(Component)
render({heading: 'Initial Heading'}, function (state, element, done) {
t.equal(state().heading, 'Initial Heading')
done()
})
})
test('args passed to render', function (t) {
t.plan(1)
thermo.createComponent(Component, {heading: 'foo'}, 'bar', function (state, element, done) {
t.equal(element.childNodes[0].toString(), 'foobar')
done()
})
})
function elements () {
return document.getElementsByClassName('component')
}