断言数组减少为true [英] Assert an array reduces to true

查看:141
本文介绍了断言数组减少为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其中一个测试中,我们需要声明存在3个元素中的一个。目前我们正在使用 protractor.promise.all() Array.reduce()

In one of the tests, we need to assert that one of the 3 elements is present. Currently we are doing it using the protractor.promise.all() and Array.reduce():

var title = element(by.id("title")),
    summary = element(by.id("summary")),
    description = element(by.id("description"));

protractor.promise.all([
    title.isPresent(),
    summary.isPresent(),
    description.isPresent()
]).then(function (arrExists) {
    expect(arrExists.reduce(function(a,b) { return a || b; })).toBe(true);
});

是否有更好的方式使用 Jasmine <解决它/ em>没有明确解决承诺?我们需要自定义匹配器还是可以使用内置匹配器解决?

Is there a better way to solve it with Jasmine without resolving the promises explicitly? Would we need a custom matcher or it is possible to solve with the built-in matchers?

推荐答案

检查:

let EC = protractor.ExpectedConditions;

let title = EC.visibilityOf($("#title")),
    summary = EC.visibilityOf($("#summary")),
    description = EC.visibilityOf($("#description"));

expect(EC.or(title, summary, description)() ).toBeTruthy('Title or summary or description should be visible on the page')

请注意,我正在执行ExpectedCondition返回的函数 - 所以我得到该函数的结果(Promise将被解析为boolean)而不是函数。

Notice that i am executing function that ExpectedCondition returns - so i am getting result of that function(Promise that will be resolved to boolean) instead of function.

如果需要,可以使用.presenceOf().visibilityOf()

You can use .presenceOf() if you need it instead .visibilityOf()

http://www.protractortest.org/#/api?view=ExpectedConditions.prototype.or

这篇关于断言数组减少为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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