-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
117 lines (88 loc) · 2.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
describe('extendible', function () {
// 'use strict'; // Disabled for strict-mode vs global mode tests;
var assume = require('assume')
, extend = require('./')
, Foo;
beforeEach(function each() {
Foo = function Foo() {};
Foo.extend = extend;
});
it('is exported as function', function () {
assume(extend).is.a('function');
});
it('returns the newly extended function', function () {
var Bar = Foo.extend();
assume(Bar).does.not.equal(Foo);
});
it('can override properties and methods', function () {
/* istanbul ignore next */
Foo.prototype.bar = function () { return true; };
Foo.prototype.prop = 10;
var Bar = Foo.extend({
bar: function () {
return false;
},
prop: 'foo'
});
var bar = new Bar();
assume(bar.bar()).is.false();
assume(bar.prop).equals('foo');
});
it('correctly inherits and overrides getters', function () {
var Bar = Foo.extend({
get hello() {
return 'hi';
}
});
var Baz = Bar.extend({
yes: false
});
var bar = new Baz();
assume(bar.yes).equals(false);
assume(bar.hello).equals('hi');
var Override = Bar.extend({
hello: 'world'
});
var override = new Override();
assume(override.hello).equals('world');
});
it('returns the value from the parent constructor', function () {
var Baz = function () {
return {
my: 'name is '+ this.name
};
};
Baz.prototype.name = 'baz';
Baz.extend = extend;
var Bob = Baz.extend({
name: 'bob'
});
var bob = new Bob()
, baz = new Baz();
assume(baz.my).equals('name is baz');
assume(bob.my).equals('name is bob');
});
it('runs in strict mode if the parent runs in strict mode', function (next) {
next = assume.plan(2, next);
var Baz = function () {
'use strict';
assume(this).equals(undefined);
};
Baz.extend = extend;
var Bar = Baz.extend()
, bar = Bar()
, baz = Baz();
next();
});
it('runs in does not run in strict mode if the parent isnt', function (next) {
next = assume.plan(2, next);
var Baz = function () {
assume(this).equals(global);
};
Baz.extend = extend;
var Bar = Baz.extend()
, bar = Bar()
, baz = Baz();
next();
});
});