Skip to content

Commit

Permalink
Add test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 27, 2017
1 parent bcf4281 commit f54d136
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/test.end.test.js
Expand Up @@ -37,3 +37,40 @@ describe('test grant that calls end', function() {
});

});


describe('test grant that calls end after error', function() {

var grant = {};
grant.request = function(req) {};
grant.error = function(err, txn, res, next) {
res.end('Error: ' + err.message);
};

describe('with an end callback', function() {
var res;

before(function(done) {
var test = new Test(grant);
test.end(function(r) {
res = r;
done();
}).error(new Error('Danger, Will Robinson!'));
});

it('should call end callback', function() {
expect(res.statusCode).to.be.equal(200);
expect(res.body).to.be.equal('Error: Danger, Will Robinson!');
});
});

describe('without an end callback', function() {
it('should throw an error', function() {
expect(function() {
var test = new Test(grant);
test.error(new Error('Danger, Will Robinson!'));
}).to.throw(Error, 'res#end should not be called');
});
});

});
64 changes: 64 additions & 0 deletions test/test.next.test.js
Expand Up @@ -63,3 +63,67 @@ describe('test grant that calls next with error', function() {
});

});


describe('test grant that calls next after error', function() {

var grant = {};
grant.request = function(req) {};
grant.error = function(err, txn, res, next) {
next(err);
};

describe('with a next callback', function() {
var err;

before(function(done) {
var test = new Test(grant);
test.next(function(e) {
err = e;
done();
}).error(new Error('Danger, Will Robinson!'));
});

it('should call next callback', function() {
expect(err).to.be.an.instanceOf(Error);
expect(err.message).to.equal('Danger, Will Robinson!');
});
});

describe('without a next callback', function() {
it('should throw an error', function() {
expect(function() {
var test = new Test(grant);
test.error(new Error('Danger, Will Robinson!'));
}).to.throw(Error, 'next should not be called');
});
});

});

describe('test grant that calls next with error after error', function() {

var grant = {};
grant.request = function(req) {};
grant.error = function(err, txn, res, next) {
next(err);
};

describe('with a next callback', function() {
var err;

before(function(done) {
var test = new Test(grant);
test.next(function(e) {
err = e;
done();
}).error(new Error('Danger, Will Robinson!'));
});

it('should call next callback', function() {
expect(err).to.be.an.instanceOf(Error);
expect(err.message).to.equal('Danger, Will Robinson!');
});
});

});

0 comments on commit f54d136

Please sign in to comment.