Permalink
Browse files

Merge pull request #123 from kriskowal/nend

Simplify nend
  • Loading branch information...
2 parents 7d86d9f + a7596e0 commit 31c5a897318bc6f061e2c8208e012ba284a67f81 @kriskowal committed Oct 11, 2012
Showing with 10 additions and 8 deletions.
  1. +0 −4 q.js
  2. +10 −4 spec/q-spec.js
View
4 q.js
@@ -1578,19 +1578,15 @@ function ninvoke(object, name /*, ...args*/) {
exports.nend = nend;
function nend(promise, nodeback) {
if (nodeback) {
- var deferred = defer();
promise.then(function (value) {
nextTick(function () {
- deferred.resolve();
nodeback(null, value);
});
}, function (error) {
nextTick(function () {
- deferred.resolve();
nodeback(error);
});
});
- return deferred.promise;
} else {
return promise;
}
View
14 spec/q-spec.js
@@ -1415,16 +1415,22 @@ describe("node support", function () {
it("calls back with a resolution", function () {
var spy = jasmine.createSpy();
- return Q.resolve(10).nend(spy)
- .then(function () {
+ Q.resolve(10).nend(spy);
+ waitsFor(function () {
+ return spy.argsForCall.length;
+ });
+ runs(function () {
expect(spy.argsForCall).toEqual([[null, 10]]);
});
});
it("calls back with an error", function () {
var spy = jasmine.createSpy();
- return Q.reject(10).nend(spy)
- .then(function () {
+ Q.reject(10).nend(spy);
+ waitsFor(function () {
+ return spy.argsForCall.length;
+ });
+ runs(function () {
expect(spy.argsForCall).toEqual([[10]]);
});
});

0 comments on commit 31c5a89

Please sign in to comment.