-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
74 lines (60 loc) · 1.68 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
var seq = require('./');
describe('Sequencing', function () {
it('should be a function', function () {
seq.should.be.a.Function;
});
describe('#fire', function () {
it('should be a function', function () {
seq().fire.should.be.a.Function;
});
});
describe('#use', function () {
it('should throw if not given a function', function () {
seq().use.should.throw();
});
it('should register middleware and invoke in order registered', function () {
var test = seq();
var context = {count: 0};
test.use(function (cxt, next) {
cxt.count++;
cxt.count.should.equal(1);
next(null, cxt);
});
test.use(function (cxt, next) {
setTimeout(function () {
cxt.count++;
cxt.count.should.equal(2);
next(null, cxt);
}, 100);
});
test.use(function (cxt, next) {
cxt.count++;
cxt.count.should.equal(3);
next(null, cxt);
});
test.fire(context);
});
});
describe('#useOnError', function () {
it('should throw if not given a function', function () {
seq().useOnError.should.throw();
});
it('should invoke error handler when error is provided to #next', function () {
var test = seq();
var context = {count:0};
test.use(function (cxt, next) {
cxt.count++;
next(new Error(), cxt);
});
test.use(function (cxt, next) {
cxt.count++; // shouldn't be called
next(null, cxt);
});
test.useOnError(function (err, cxt) {
cxt.count.should.equal(1);
err.should.be.instanceOf(Error);
});
test.fire(context);
});
});
});