Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add (err, res) signature

  • Loading branch information...
commit 5899d39d7c5feafb3f5eeffa39344d71e5d4078b 1 parent 4c31163
@tj tj authored
Showing with 10 additions and 11 deletions.
  1. +6 −8 lib/test.js
  2. +4 −3 test/supertest.js
View
14 lib/test.js
@@ -69,11 +69,7 @@ Test.prototype.expect = function(val, fn){
}
// callback
- if ('function' == typeof fn) {
- this.end(function(res){
- self.assert(res, fn);
- });
- }
+ if ('function' == typeof fn) this.end(fn);
return this;
};
@@ -93,7 +89,9 @@ Test.prototype.end = function(fn){
var addr = app.address();
if (!addr) return app.listen(0, function(){ self.end(fn); });
this.url = 'http://' + addr.address + ':' + addr.port + this.url;
- end.call(this, fn);
+ end.call(this, function(res){
+ self.assert(res, fn);
+ });
};
/**
@@ -109,9 +107,9 @@ Test.prototype.assert = function(res, fn){
// status
if (status && res.status !== status) {
- return fn(new Error('expected ' + status + ' response, got ' + res.status));
+ return fn(new Error('expected ' + status + ' response, got ' + res.status), res);
}
- fn();
+ fn(null, res);
};
View
7 test/supertest.js
@@ -12,7 +12,7 @@ describe('request(app)', function(){
request(app)
.get('/')
- .end(function(res){
+ .end(function(err, res){
res.should.have.status(200);
res.text.should.equal('hey');
done();
@@ -29,7 +29,7 @@ describe('request(app)', function(){
var server = app.listen(4000, function(){
request(server)
.get('/')
- .end(function(res){
+ .end(function(err, res){
res.should.have.status(200);
res.text.should.equal('hey');
done();
@@ -47,7 +47,8 @@ describe('request(app)', function(){
request(app)
.get('/')
- .expect(404, function(err){
+ .expect(404)
+ .end(function(err, res){
err.message.should.equal('expected 404 response, got 200');
done();
});
Please sign in to comment.
Something went wrong with that request. Please try again.