Skip to content

Commit 3ea4524

Browse files
authored
Merge pull request #130 from richardpringle/master
Update superagent to handle expected error responses.
2 parents d34ae40 + 5bad33f commit 3ea4524

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/request.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ function Test (app, method, path) {
244244
Request.call(this, method, path);
245245
this.app = app;
246246
this.url = typeof app === 'string' ? app + path : serverAddress(app, path);
247+
this.ok(function() {
248+
return true;
249+
});
247250
}
248251
util.inherits(Test, Request);
249252

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"is-ip": "1.0.0",
5151
"methods": "^1.1.2",
5252
"qs": "^6.2.0",
53-
"superagent": "^2.0.0"
53+
"superagent": "^3.3.0"
5454
},
5555
"devDependencies": {
5656
"simplifyify": "^2.0.1",

test/request.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ describe('request', function () {
7474
});
7575
});
7676

77+
it('succeeds when response has an error status', function (done) {
78+
request('https://httpbin.org')
79+
.get('/status/400')
80+
.end(function (err, res) {
81+
res.should.have.status(400);
82+
done(err);
83+
});
84+
});
85+
7786
it('can be augmented with promises', function (done) {
7887
request('https://httpbin.org')
7988
.get('/get')
@@ -93,6 +102,14 @@ describe('request', function () {
93102
})
94103
.then(done, done);
95104
});
105+
106+
it('can resolve a promise given status code of 400', function () {
107+
return request('https://httpbin.org')
108+
.get('/status/400')
109+
.then(function (res) {
110+
res.should.have.status(400);
111+
});
112+
});
96113
});
97114

98115
isNode && describe('Node.js', function () {

0 commit comments

Comments
 (0)