I need to test the result from a promise. Will a promise resolve in time to be part of a conditional?
if (myPromise() > 15 && myOtherPromise()) {
// do stuff when myPromise resolves to over 15 and myOtherPromise is true
} else {
// do stuff when myPromise resolves to 15 or less or myOtherPromise is false
}
Or do I just need to suck it up and do:
let myP = myPromise();
let myOtherP = myOtherPromise();
promise.all([myP, myOtherP]).then(function(res) {
if (res[0] > 15 && res[1]) {
// do stuff when myPromise resolves to over 15 and myOtherPromise is true
} else {
// do stuff when myPromise resolves to 15 or less or myOtherPromise is false
}
});
reposted from comment below for everyone "downvoting" the question and thinking this is a repeat.
Well, yes and no. No, because I'm working with Jasmine, where the expect calls automagically resolves a promise when one is passed.
expect(myPromise()).toBeGreaterThan(15)
. So from the outside, it might have been conceivable that an if's conditional might resolve a promise before performing any comparisons.