Skip to content
Browse files

Fixed body on non-2xx response. Closes #56

  • Loading branch information...
1 parent 05c14b5 commit 5ad1a0cc7c276693940e27fc323f14d1debced2b @tj tj committed Jul 19, 2011
Showing with 22 additions and 25 deletions.
  1. +19 −23 lib/browser.js
  2. +3 −2 test/browser.navigation.test.js
View
42 lib/browser.js
@@ -231,8 +231,25 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){
});
}
- // Success
- if (status >= 200 && status < 300) {
+ // Redirect
+ if (status >= 300 && status < 400) {
+ var location = res.headers.location
+ , uri = url.parse(location)
+ , path = uri.pathname + (uri.search || '');
+ otherHostname = uri.hostname;
+ if (otherHostname &&
+ (otherHostname !== 'undefined') &&
+ (otherHostname !== self.host)) {
+ self = self.hostBrowser(uri);
+ }
+ self.emit('redirect', location);
+ if (self.followRedirects) {
+ self.request('GET', path, {}, fn);
+ } else {
+ return fn(res);
+ }
+ // Other
+ } else {
var contentType = res.headers['content-type'];
if (!contentType) return fn(res);
@@ -266,27 +283,6 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){
return self.context.find(selector);
});
});
-
- // Redirect
- } else if (status >= 300 && status < 400) {
- var location = res.headers.location
- , uri = url.parse(location)
- , path = uri.pathname + (uri.search || '');
- otherHostname = uri.hostname;
- if (otherHostname &&
- (otherHostname !== 'undefined') &&
- (otherHostname !== self.host)) {
- self = self.hostBrowser(uri);
- }
- self.emit('redirect', location);
- if (self.followRedirects) {
- self.request('GET', path, {}, fn);
- } else {
- return fn(res);
- }
- // Error
- } else {
- fn(res);
}
});
View
5 test/browser.navigation.test.js
@@ -34,7 +34,7 @@ app.get('/404', function(req, res){
});
app.get('/500', function(req, res){
- res.send(500);
+ res.send('<p>OH NO!</p>', 500);
});
app.get('/redirect', function(req, res){
@@ -197,8 +197,9 @@ module.exports = {
'test .request() error': function(done){
var browser = tobi.createBrowser(app);
- browser.request('GET', '/500', {}, function(res){
+ browser.request('GET', '/500', {}, function(res, $){
res.should.have.status(500);
+ $('p').text().should.equal('OH NO!');
done();
});
},

0 comments on commit 5ad1a0c

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