diff --git a/test/test.end.test.js b/test/test.end.test.js index 034b4c3..3d9dc39 100644 --- a/test/test.end.test.js +++ b/test/test.end.test.js @@ -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'); + }); + }); + +}); diff --git a/test/test.next.test.js b/test/test.next.test.js index 214a1c3..2947213 100644 --- a/test/test.next.test.js +++ b/test/test.next.test.js @@ -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!'); + }); + }); + +});