Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 在expect语句中一起添加变量大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些字符串,我使用量角器/ jasmine / angularJS提取并转换为整数.我现在正在尝试将这些添加在一起并在期望声明中进行比较.但是我这样做会有一些承诺错误.

var result0 = element.all(by.binding('InBoxes.InBox.Count')).first().getText().then(parseFloat);
    result0.then((value) => console.log("count: ",value));

    var result1 = element.all(by.binding('InBoxItem.Count')).get(0).getText().then(parseFloat);
    result1.then((value) => console.log("count: ",value));

    var result2 = element.all(by.binding('InBoxItem.Count')).get(1).getText().then(parseFloat);
    result2.then((value) => console.log("count: ",value));

    var result3 = element.all(by.binding('InBoxItem.Count')).get(2).getText().then(parseFloat);
    result3.then((value) => console.log("count: ",value)).then(expect(result1 + result2 + result3).toEqual(result0));

    //compare badge counts to InBox badge count
    expect(result1 + result2 + result3).toEqual(result0);
  });
 });
});

我收到以下承诺错误.我认为既然承诺已经满足并且下面的计数打印出来(41,7,14和20)我可以将底部3(reulst1-3)加在一起并与result0进行比较,结果是结果总数1-3 .我有这些承诺的时间,因为我是新手,并不太了解它们.

Started
count:  41
count:  7
count:  14
count:  20
F

@R_566_4895@:
1) Workflow Application When SELEcTing Alerts panel should expand the InBox panel and PosTings
  message:
  Expected 'ManagedPromise::859 {[[PromiseStatus]]:  "pending"}ManagedPromise::896 {[[PromiseStatus]]: "pending"}ManagedPromise::933 {[[PromiseStatus]]: "pending"}' to equal ManagedPromise::822 {[[PromiseStatus]]: "pending"}.

解决方法

您正在尝试将promises一起添加,而不是实际解析的值.

在这种情况下,我会使用protractor.promise.all()来解决这个问题,以便立即解决所有需要做出预期的承诺:

protractor.promise.all([result0,result1,result2,result3]).then(function (values) {
    expect(values[1] + values[2] + values[3]).toEqual(values[0]);
});

并且,为了简化这一点,您可以将spread() the resolved values转换为“then”函数参数:

protractor.promise.all([result0,result3]).then(spread(function (value0,value1,value2,value3) {
    expect(value1 + value2 + value3).toEqual(value0);
}));

请注意,与q不同,protractor.promise没有内置的spread(),你必须有一个自定义的.

大佬总结

以上是大佬教程为你收集整理的angularjs – 在expect语句中一起添加变量全部内容,希望文章能够帮你解决angularjs – 在expect语句中一起添加变量所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。