-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmastodomSpec.js
104 lines (84 loc) · 2.49 KB
/
mastodomSpec.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
describe("mastodom.js", function(){
describe('library usage', function() {
describe('type', function() {
it('creates a node for the defined type', function() {
var node = Mastodom({
type: ['span']
});
expect(node.tagName).toEqual('SPAN');
expect(node.parent).toBeUndefined();
});
it('creates a tree for the defined array of types', function() {
var node = Mastodom({
type: ['div', 'span']
});
expect(node.tagName).toEqual('DIV');
expect(node.childNodes[0]).toBeDefined();
expect(node.childNodes[0].tagName).toEqual('SPAN');
});
});
describe('content', function() {
it('sets the content attribute as the inner html of the node', function() {
var node = Mastodom({
type: 'span',
content: 'Hello World'
});
expect(node.innerHTML).toEqual('Hello World');
});
});
describe('attributes', function() {
it('adds each of the key, value attributes to the dom node', function() {
var node = Mastodom({
type: 'p',
content: 'Hello World',
attributes: {
id: 'hello-world-node',
class: 'hello world node'
}
});
expect(node.attributes.length).toEqual(2)
});
});
describe('events', function() {
it('binds each of the key, value events to the dom node', function() {
var clicked = false;
Mastodom({
type: 'a',
content: 'Click me!',
events: {
click: function(event) {
clicked = true;
}
}
}).click();
expect(clicked).toEqual(true);
});
});
describe('children', function() {
it('accepts dom elements as children', function() {
expect(Mastodom({
type: 'div',
content: 'Hello World',
children: [
document.createElement('div')
]
}).children.length).toEqual(1);
});
it('recursively parses new specifications as children', function() {
var nodes = Mastodom({
type: 'div',
content: 'Hello World',
children: [{
type: 'span',
children: [{
type: 'a',
content: 'Howdy!'
}]
}]
})
expect(nodes.children.length).toEqual(1);
expect(nodes.children[0].children.length).toEqual(1);
});
});
});
});