Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle the error on the `end` callback

Added an additional test to ensure it works.
  • Loading branch information...
commit a3419599ac24940246842f0382fb1757f36d6c0f 1 parent c009623
@ravenac95 authored
Showing with 37 additions and 1 deletion.
  1. +3 −0  lib/test.js
  2. +34 −1 test/supertest.js
View
3  lib/test.js
@@ -121,6 +121,9 @@ Test.prototype.end = function(fn){
var self = this;
var end = Request.prototype.end;
end.call(this, function(err, res){
+ if(err) {
+ return self.emit('error', err);
+ }
self.assert(res, fn);
});
return this;
View
35 test/supertest.js
@@ -3,7 +3,8 @@ var request = require('..')
, https = require('https')
, fs = require('fs')
, path = require('path')
- , express = require('express');
+ , express = require('express')
+ , should = require('should');
describe('request(app)', function(){
it('should fire up the app on an ephemeral port', function(done){
@@ -149,6 +150,38 @@ describe('request(app)', function(){
});
})
+ it('should throw an error during redirects', function(done){
+ var app = express();
+
+ app.get('/', function(req, res){
+ res.redirect('/redirect1');
+ });
+
+ app.get('/redirect1', function(req, res){
+ res.redirect('/redirect2');
+ });
+
+ app.get('/redirect2', function(req, res){
+ setTimeout(function() {
+ res.send(200, 'Should not see me!');
+ }, 200);
+ });
+
+ var timeout = 10;
+
+ request(app)
+ .get('/')
+ .timeout(timeout)
+ .redirects(5)
+ .on('error', function(err) {
+ err.timeout.should.equal(timeout);
+ done();
+ })
+ .end(function(err, res) {
+ should.fail('There was supposed to be an error');
+ });
+ })
+
describe('.expect(status[, fn])', function(){
it('should assert the response status', function(done){
var app = express();

0 comments on commit a341959

Please sign in to comment.
Something went wrong with that request. Please try again.