Skip to content

Commit

Permalink
Test case for end and next.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Sep 16, 2013
1 parent 3ef7ff4 commit 4a58fa7
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 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');
});
});

});
63 changes: 63 additions & 0 deletions 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');
});
});

});

0 comments on commit 4a58fa7

Please sign in to comment.