Permalink
Browse files

Fix bug with inheritance and use of .end not comforming to the right …

…interface
  • Loading branch information...
1 parent cecb569 commit 2d18415c3c27e59ea594b71bd69070bc691c5772 @lightsofapollo committed Jul 9, 2014
Showing with 17 additions and 32 deletions.
  1. +5 −1 index.js
  2. +10 −29 index_test.js
  3. +2 −2 package.json
View
@@ -19,12 +19,16 @@ function PromiseRequest() {
PromiseRequest.prototype = Object.create(superagent.Request.prototype);
/** Send request and get a promise that `end` was emitted */
-PromiseRequest.prototype.end = function() {
+PromiseRequest.prototype.end = function(cb) {
var _super = superagent.Request.prototype.end;
var context = this;
return new Promise(function(accept, reject) {
_super.call(context, function(err, value) {
+ if (cb) {
+ cb(err, value);
+ }
+
if (err) {
return reject(err);
}
View
@@ -41,50 +41,31 @@ suite('superagent-promise', function() {
server.close(done);
});
-
- test('issue request', function(done) {
+ test('issue request', function() {
var addr = server.address();
var url = 'http://' + addr.address + ':' + addr.port + "/success";
- request('GET', url).end().then(
- function(res) {
- assert.equal(res.text, successBody);
- done();
- },
-
- function(err) {
- done(err);
- }
- );
+ return request('GET', url).end().then(function(res) {
+ assert.equal(res.text, successBody);
+ });
});
- test('issue request with .get', function(done) {
+ test('issue request with .get', function() {
var addr = server.address();
var url = 'http://' + addr.address + ':' + addr.port + "/success";
- request.get(url).end().then(
- function(res) {
- assert.equal(res.text, successBody);
- done();
- },
-
- function(err) {
- done(err);
- }
- );
+ return request.get(url).end().then(function(res) {
+ assert.equal(res.text, successBody);
+ });
});
- test('issue 404 request', function(done) {
+ test('issue 404 request', function() {
var addr = server.address();
var url = 'http://' + addr.address + ':' + addr.port + "/NotFound";
- request('GET', url).end().then(function(res) {
+ return request('GET', url).end().then(function(res) {
assert.ok(!res.ok);
assert.equal(res.text, errorBody);
- done();
- }, function(err) {
- console.log(err);
- done(err);
});
});
View
@@ -1,6 +1,6 @@
{
"name": "superagent-promise",
- "version": "0.1.1",
+ "version": "0.1.2",
"description": "superagent promise wrapper",
"main": "index.js",
"scripts": {
@@ -28,7 +28,7 @@
"browser-test": "0.0.0-alpha.2",
"component": "^1.0.0-rc5",
"debug": "0.7.4",
- "mocha": "~1.17.1",
+ "mocha": "^1.20.1",
"node-static": "^0.7.3",
"promise": ">= 3.2.0",
"superagent": ">= 0.16.0"

0 comments on commit 2d18415

Please sign in to comment.