bugfix(assertAsync): add promiseLike support for angularJS promises

implement a promiseLike method so libraries using non-browser promise
implementations can still utilize assertAsync functionality.

Fixes: #1612
This commit is contained in:
Cody Mikol
2018-10-18 16:53:25 -04:00
parent 3ae61b14ad
commit 591bf1144b
3 changed files with 105 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ getJasmineRequireObj().AsyncExpectation = function(j$) {
throw new Error('expectAsync is unavailable because the environment does not support promises.');
}
if (!j$.isPromise(this.actual)) {
if (!j$.isPromiseLike(this.actual)) {
throw new Error('Expected expectAsync to be called with a promise.');
}

View File

@@ -120,7 +120,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};
j$.isPromise = function(obj) {
return typeof jasmineGlobal.Promise !== 'undefined' && obj && obj.constructor === jasmineGlobal.Promise;
return typeof jasmineGlobal.Promise !== 'undefined' && !!obj && obj.constructor === jasmineGlobal.Promise;
};
j$.isPromiseLike = function(obj) {
return !!obj && j$.isFunction_(obj.then);
};
j$.fnNameFor = function(func) {