diff --git a/test/test.end.test.js b/test/test.end.test.js new file mode 100644 index 0000000..7f2d9c6 --- /dev/null +++ b/test/test.end.test.js @@ -0,0 +1,37 @@ +var Test = require('../lib/test'); + +describe('test grant that calls end', function() { + + var grant = {}; + grant.request = function(req) {} + grant.response = function(txn, res, next) { + res.end('Hello'); + } + + describe('with an end callback', function() { + var res; + + before(function(done) { + var test = new Test(grant); + test.end(function(r) { + res = r; + done(); + }).decide(); + }); + + it('should call end callback', function() { + expect(res.statusCode).to.be.equal(200); + expect(res.body).to.be.equal('Hello'); + }); + }); + + describe('without an end callback', function() { + it('should throw an error', function() { + expect(function() { + var test = new Test(grant); + test.decide(); + }).to.throw(Error, 'res#end should not be called'); + }); + }); + +}); diff --git a/test/test.next.test.js b/test/test.next.test.js new file mode 100644 index 0000000..2f46c5b --- /dev/null +++ b/test/test.next.test.js @@ -0,0 +1,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'); + }); + }); + +});