Skip to content

Commit

Permalink
Make sure that arguments and this is always OK.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W committed May 30, 2015
1 parent 38a0055 commit 6b37643
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ Test.prototype.end = function(fn){
};

/**
* Perform assertions and invoke `fn(err)`.
* Perform assertions and invoke `fn(err, res)`.
*
* @param {?Error} resError
* @param {Response} res
* @param {Function} fn
* @api private
Expand Down Expand Up @@ -165,8 +166,6 @@ Test.prototype.assert = function(resError, res, fn){
error = this._assertFunction(this._asserts[i], res);
}

if (error) return fn(error);

fn.call(this, error, res);
};

Expand Down
38 changes: 38 additions & 0 deletions test/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,44 @@ describe('request(app)', function(){
});
});
});

it('should include the response in the error callback', function(done){
var app = express();

app.get('/', function(req, res){
res.send('whatever');
});

request(app)
.get('/')
.expect(function() {
throw new Error('Some error');
})
.end(function(err, res){
should.exist(err);
should.exist(res);
// Duck-typing response, just in case.
res.status.should.equal(200);
done();
});
});

it('should set `this` to the test object when calling the error callback', function(done) {
var app = express();

app.get('/', function(req, res){
res.send('whatever');
});

var test = request(app).get('/');
test.expect(function() {
throw new Error('Some error');
}).end(function(err, res){
should.exist(err);
this.should.eql(test);
done();
});
});
});

describe('.expect(status[, fn])', function(){
Expand Down

0 comments on commit 6b37643

Please sign in to comment.