-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
88 lines (66 loc) · 1.31 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
var assert = require('assert');
var helper = require('./index.js');
var name = 'john';
var age = 18;
var somthing = 'somthing...';
/*
* Parent
*/
var Parent = helper.create(
function(name) {
this.name = name;
},
function(proto) {
proto.getName = function() {
return this.name;
}
}
);
assert.equal(typeof(Parent.extend), 'function');
var p1 = Parent(name); // or: new Parent(name);
assert.equal(p1.name, name);
assert.equal(p1.getName(), name);
/*
* Child
*/
var Child = Parent.extend(
function(name, age) {
this.age = age;
},
function(proto) {
proto.getAge = function() {
return this.age;
}
}
);
assert.equal(typeof(Child.extend), 'function');
var c1 = new Child(name, age);
assert.equal(c1.name, name);
assert.equal(c1.getName(), name);
assert.equal(c1.age, age);
assert.equal(c1.getAge(), age);
/*
* Append
*/
Parent.prototype.getSomething = function() {
return somthing;
};
assert.equal(p1.getSomething(), somthing);
assert.equal(c1.getSomething(), somthing);
/*
* Extend class exists
*/
var MyClass = helper.extend(
function() {
// init;
},
Object,
function(proto) {
// set protos;
}
);
assert.equal(typeof(MyClass.extend), 'function');
/*
* End
*/
console.log('all tests passed!');