Skip to content
Permalink
Browse files

fix($q): make instanceof work for $q promises

Closes: #13574
Closes: #13545
  • Loading branch information...
thorn0 authored and lgalfaso committed Dec 17, 2015
1 parent 04efdd5 commit b3ef5e08528f5f1916876032700a016448fb196a
Showing with 13 additions and 5 deletions.
  1. +4 −5 src/ng/q.js
  2. +9 −0 test/ng/qSpec.js
@@ -566,11 +566,6 @@ function qFactory(nextTick, exceptionHandler) {
throw $qMinErr('norslvr', "Expected resolverFn, got '{0}'", resolver);
}

if (!(this instanceof Q)) {
// More useful when $Q is the Promise itself.
return new Q(resolver);
}

var deferred = new Deferred();

function resolveFn(value) {
@@ -586,6 +581,10 @@ function qFactory(nextTick, exceptionHandler) {
return deferred.promise;
};

// Let's make the instanceof operator work for promises, so that
// `new $q(fn) instanceof $q` would evaluate to true.
$Q.prototype = Promise.prototype;

$Q.defer = defer;
$Q.reject = reject;
$Q.when = when;
@@ -221,6 +221,15 @@ describe('q', function() {
expect(typeof promise.finally).toBe('function');
});

it('should support the instanceof operator', function() {
/*jshint newcap: false */
var promise = new q(noop);
expect(promise instanceof q).toBe(true);
promise = q(noop);
expect(promise instanceof q).toBe(true);
/*jshint newcap: true */
});


describe('resolve', function() {
it('should fulfill the promise and execute all success callbacks in the registration order',

0 comments on commit b3ef5e0

Please sign in to comment.
You can’t perform that action at this time.