/
test.next.test.js
63 lines (50 loc) · 1.33 KB
/
test.next.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
var Test = require('../lib/test');
describe('test grant that calls next', function() {
var grant = {};
grant.request = function(req) {}
grant.response = function(txn, res, next) {
next()
}
describe('with a next callback', function() {
var err;
before(function(done) {
var test = new Test(grant);
test.next(function(e) {
err = e;
done();
}).decide();
});
it('should call next callback', function() {
expect(err).to.be.undefined;
});
});
describe('without a next callback', function() {
it('should throw an error', function() {
expect(function() {
var test = new Test(grant);
test.decide();
}).to.throw(Error, 'next should not be called');
});
});
});
describe('test grant that calls next with error', function() {
var grant = {};
grant.request = function(req) {}
grant.response = function(txn, res, next) {
next(new Error('oops'))
}
describe('with a next callback', function() {
var err;
before(function(done) {
var test = new Test(grant);
test.next(function(e) {
err = e;
done();
}).decide();
});
it('should call next callback', function() {
expect(err).to.be.an.instanceOf(Error);
expect(err.message).to.equal('oops');
});
});
});