Add expectAsync().toBePending()
This commit is contained in:
25
src/core/matchers/async/toBePending.js
Normal file
25
src/core/matchers/async/toBePending.js
Normal file
@@ -0,0 +1,25 @@
|
||||
getJasmineRequireObj().toBePending = function(j$) {
|
||||
/**
|
||||
* Expect a promise to be pending, ie. the promise is neither resolved nor rejected.
|
||||
* @function
|
||||
* @async
|
||||
* @name async-matchers#toBePending
|
||||
* @since 3.5.1 (should this be the next version or the version when it was added?)
|
||||
* @example
|
||||
* await expectAsync(aPromise).toBePending();
|
||||
*/
|
||||
return function toBePending() {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
if (!j$.isPromiseLike(actual)) {
|
||||
throw new Error('Expected toBePending to be called on a promise.');
|
||||
}
|
||||
var want = {};
|
||||
return Promise.race([actual, Promise.resolve(want)]).then(
|
||||
function(got) { return {pass: want === got}; },
|
||||
function() { return {pass: false}; }
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
getJasmineRequireObj().requireAsyncMatchers = function(jRequire, j$) {
|
||||
var availableMatchers = [
|
||||
'toBePending',
|
||||
'toBeResolved',
|
||||
'toBeRejected',
|
||||
'toBeResolvedTo',
|
||||
|
||||
Reference in New Issue
Block a user