Added expectAsync(...).already

* Causes async matchers to immediately fail if the promise is pending
* Fixes #1845
This commit is contained in:
Steve Gravrock
2021-06-23 20:13:01 -07:00
parent 5862b22aef
commit dbc1a0aa56
5 changed files with 228 additions and 0 deletions

View File

@@ -203,6 +203,19 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
return matches ? matches[1] : '<anonymous>';
};
j$.isPending_ = function(promise) {
var sentinel = {};
// eslint-disable-next-line compat/compat
return Promise.race([promise, Promise.resolve(sentinel)]).then(
function(result) {
return result === sentinel;
},
function() {
return false;
}
);
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is an instance of the specified class/constructor.