-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
81 lines (66 loc) · 1.89 KB
/
test.js
File metadata and controls
81 lines (66 loc) · 1.89 KB
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
var tape = require('tape')
var Hyperc = require('./index')
var Component = require('./component')
var JSDOM = require('jsdom').JSDOM
var DOM = new JSDOM(`
<html>
<body>
<canvas id="stage" width="600" height="600"></canvas>
</body>
</html>
`)
global.window = DOM.window
global.document = DOM.window.document
global.window.createjs = {
Stage: class Stage {
addChild () {}
removeChild () {}
},
Shape: function () {},
Container: function () {}
}
tape('Create an app', (t) => {
t.plan(3)
t.throws(() => {
new Hyperc() // eslint-disable-line no-new
}, null, 'Should throw exception when no selector is given')
t.doesNotThrow(() => {
new Hyperc('#stage') // eslint-disable-line no-new
}, null, 'Should accept query selector')
t.doesNotThrow(() => {
new Hyperc(document.querySelector('#stage')) // eslint-disable-line no-new
}, null, 'Should accept node')
})
tape('Exposed APIs', (t) => {
var app = new Hyperc('#stage')
t.plan(4)
t.equal(typeof app.use, 'function', 'Should expose use function')
t.equal(typeof app.render, 'function', 'Should expose render function')
t.doesNotThrow(() => {
class Item extends Component {}
app.render(Item)
}, null, 'render: accepts only Components')
t.doesNotThrow(() => {
app.use(function () {})
}, null, 'use: accepts only functions')
})
tape('Component class', (t) => {
class Item extends Component {}
t.plan(4)
t.throws(() => {
new Item() // eslint-disable-line no-new
}, null, 'Component should implement identity method')
class Rect extends Component {
identity () {}
}
var rect = new Rect()
t.throws(() => {
Item.getItems()
}, null, 'Component should implement getItems method')
t.throws(() => {
rect.create()
}, null, 'Component should implement create method')
t.throws(() => {
rect.update()
}, null, 'Component should implement update method')
})