In protractor.js,
I have functions that promise/defer. For example
var myFunc = function(_params) {
var deferred = protractor.promise.defer();
/***do magical code things****/
/***wait for other promises***/
/*****deferred.fulfill();*****/
return deferred.promise;
};
What sort of combinations of typeof
statements can I use to check if this thing (when passed to something else) promises?
typeof promiseMaybe === 'function'
typeof promiseMaybe.then === 'function'
&&
'ed with prior?
Or is there a non-typeof
function like...
promiseMaybe.isThenable
protractor.promise.isThenable(promiseMaybe)
Clarification
I have a method that will receive myFunc
as a parameter, but this method can also receive strings and finders. I need to know how to tell if a parameter is the function that promises something, possibly before calling the function.
There is a helper method in Protractor for that -
protractor.promise.isPromise()
:Protractor takes this method directly from
selenium-webdriver
, here you can find the source code of the method:So basically, any object with a
then
method is considered a Promise.