diff --git a/q.js b/q.js index 6369a7c9..b3f73cfa 100644 --- a/q.js +++ b/q.js @@ -1573,7 +1573,12 @@ function nbind(callback /* thisp, ...args*/) { */ exports.npost = npost; function npost(object, name, args) { - return napply(object[name], object, args); + var nodeArgs = array_slice(args); + var deferred = defer(); + nodeArgs.push(deferred.makeNodeResolver()); + + post(object, name, nodeArgs).fail(deferred.reject); + return deferred.promise; } /** @@ -1588,11 +1593,11 @@ function npost(object, name, args) { */ exports.ninvoke = ninvoke; function ninvoke(object, name /*, ...args*/) { - var args = array_slice(arguments, 2); + var nodeArgs = array_slice(arguments, 2); var deferred = defer(); - args.push(deferred.makeNodeResolver()); + nodeArgs.push(deferred.makeNodeResolver()); - post(object, name, args).fail(deferred.reject); + post(object, name, nodeArgs).fail(deferred.reject); return deferred.promise; } diff --git a/spec/q-spec.js b/spec/q-spec.js index 1dda391f..dda40fac 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -1596,6 +1596,23 @@ describe("node support", function () { }); }); + it("rejects with thrown error", function () { + return Q.npost(obj, "errorThrower", [1, 2, 3]) + .then(function (sum) { + expect(true).toBe(false); + }, function (_exception) { + expect(_exception).toBe(exception); + }); + }); + + it("works on promises for objects with Node methods", function () { + return Q.resolve(obj) + .npost("method", [1, 2, 3]) + .then(function (sum) { + expect(sum).toEqual(6); + }); + }); + }); describe("ninvoke", function (done) {