比较两个 promise 的值 [英] Comparing values of two promises

查看:38
本文介绍了比较两个 promise 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望实现以下目标:

var textPromise1 = element(by.id('id1')).getText();
var textPromise2 = element(by.id('id2')).getText();

if(textPromise1.SOMELOGIC == textPromise2.SOMELOGIC )
console.log('These are equal')

我知道使用 .then() 解决了承诺.但是,我想知道是否有某种方法可以实现上述目标!

I know the promise is resolved using .then(). However, I want to know if there exists some way with which above can be achieved!

谢谢,

推荐答案

您需要解决两个文本的 promise.这里更好的方法是使用 expect 并让 expect 为您解决承诺.我就是这样自己解决这类问题的-

You need to resolve the promises for both the texts. The better way here is to use expect and let the expect resolve the promise for you. This is how I solved this kind of problem for myself-

    textPromise1.then(function(data){
    //here you can call an external function that will apply some logic to your data string
    var string1= data.someLogicFunction1();//or perform whatever operations are required on data
    expect(someLogicFunction2(textPromise2)).toBe(string1);

})

这篇关于比较两个 promise 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆