-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
66 lines (57 loc) · 1.17 KB
/
index.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
// 在“树”结构中,根结点有子节点,没父节点;叶子节点有父节点,没子节点;中间的,父节点、子节点都有
const mixin = require('./index')
function Parent() {
this.children = []
}
test('simple', () => {
function RootTreeNode() {
mixin(this, Parent)
}
const node = new RootTreeNode()
expect(
node._mixin(Parent)
).toBe(true)
expect(
node._mixin(RootTreeNode)
).toBe(false)
expect(
node.children
).toEqual([])
})
function Child(parent) {
this.parent = parent
}
test('arguments', () => {
function LeafTreeNode(parent) {
mixin(this, Child, [parent])
}
const node = new LeafTreeNode('parent')
expect(
node._mixin(Child)
).toBe(true)
expect(
node.parent
).toBe('parent')
})
test('multi mixin', () => {
function ChildTreeNode(parent) {
mixin(this, Parent)
mixin(this, Child, [parent])
}
const node = new ChildTreeNode('parent')
expect(
node._mixin(Parent)
).toBe(true)
expect(
node._mixin(Child)
).toBe(true)
expect(
node._mixin(ChildTreeNode)
).toBe(false)
expect(
node.parent
).toBe('parent')
expect(
node.children
).toEqual([])
})