-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
102 lines (92 loc) · 2.45 KB
/
tests.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
// jscs:disable validateIndentation
'use strict';
var assert = require("assert");
var handlers = require('./');
describe('react-handlers', function() {
it('executes single function', function() {
var test = '';
var h = handlers(function() {
test += 'a'
});
h();
assert.equal(test, 'a');
});
it('executes multiple functions in order', function() {
var test = '';
var h = handlers(function() {
test += 'a'
},
function() {
test += 'b'
},
function() {
test += 'c'
}
);
h();
assert.equal(test, 'abc');
});
it('executes function with bound context', function() {
var test = '';
var ctx = {val: 'a'};
var h = handlers(function() {
test += this.val;
}.bind(ctx)
);
h();
assert.equal(test, 'a');
});
it('executes function with handlers "this" context', function() {
var test = '';
var ctx = {val: 'a'};
(function() {
var h = handlers(function() {
test += this.val;
}
);
h.apply(this);
}).apply(ctx);
assert.equal(test, 'a');
});
it('skips undefineds', function() {
var test = '';
var h = handlers(function() {
test += 'a'
},
undefined,
function() {
test += 'b'
}
);
h();
assert.equal(test, 'ab');
});
it('throws if non-function is passed', function() {
var test = '';
var h = handlers(function() {
},
{},
function() {
}
);
assert.throws(function() {
h();
});
});
it('args are passed to function', function() {
var h = handlers(function() {
assert.equal(arguments.length, 3);
assert.equal(arguments[0], 'a');
assert.equal(arguments[1], 'b');
assert.equal(arguments[2], 'c');
},
function() {
assert.equal(arguments.length, 3);
assert.equal(arguments[0], 'a');
assert.equal(arguments[1], 'b');
assert.equal(arguments[2], 'c');
}
);
h('a', 'b', 'c');
});
})