fix($q): make instanceof work for $q promises
Closes: #13574 Closes: #13545
This commit is contained in:
+4
-5
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user