Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用';或';在量角器预期条件下_Angularjs_Protractor - Fatal编程技术网

Angularjs 使用';或';在量角器预期条件下

Angularjs 使用';或';在量角器预期条件下,angularjs,protractor,Angularjs,Protractor,我试图在量角器中使用。但是,文档中没有任何关于如何在这些块中使用“或”或“和”的示例 我已经试过了 expect(myString).or.toEqual('a string').toEqual('another string') expect(myString).toEqual('a string').or.toEqual('another string') 只是为了好玩 expect(myString).toEqual('a string', 'another string') 有人问

我试图在量角器中使用。但是,文档中没有任何关于如何在这些块中使用“或”或“和”的示例

我已经试过了

expect(myString).or.toEqual('a string').toEqual('another string')

expect(myString).toEqual('a string').or.toEqual('another string')
只是为了好玩

expect(myString).toEqual('a string', 'another string')
有人问过这个问题,但只给出了一个解决办法

我想实际使用内置在量角器中的or函数,因为它应该允许消息读取如下内容

Expected 'a totally different string' to be 'a string' or 'another string'
您始终可以编写自定义匹配器。在这种情况下,不需要编写一个,在中提供的一个将适合您的用例。对于jasmine 1.x:

this.addMatchers({
    toBeIn: function(expected) {
        var posibilities = Array.isArray(expected) ? expected : [expected];
        return posibilities.indexOf(this.actual) > -1;
    }
});
用法:

expect(myString).toBeIn(["a string", "another string"]);


仅供参考,还有一个有用的定制茉莉花匹配器库:。

这里提供了示例:。但是,您混淆了expected conditions的用法,它用于
浏览器。等待
和not expects。

这有点像黑客,但它只是帮助了我。我发布它是为了防止它对某人有用,不是因为我认为它是最优雅的方法(也可能是一种“变通方法”)。如果您的字符串真的不同,它就可以工作,并且它可以用于字符串,而不是更一般的情况。就我的情况而言,我必须先解决承诺

myString.getText().then(function(text){
                  expect('a stringanother string'.search(text)).toBeGreaterThan(-1);
                });

当然,上面提到的人会很乐意通过像‘n’或‘另一个’这样的部分匹配,或者像‘ngano’这样的废话。这些都不会发生在我身上。

我不知道你的问题的答案,但我认为这不是一个好主意。为什么要在测试中加入or子句?不管我不赞成or,通过代码检查,我认为您想要的是
or(expect(myString).toEqual('a string')、expect(myString).toEqual('a string'))
只是我的猜测,不是tested@emory我已经尝试过了,但没有运气,很明显有解决办法。我的问题是如何使用文档中描述的功能。@KyleRogers可能误解了这个问题。您是否要求编写与
相关联的预期条件,或将其传递给
浏览器。wait()
?谢谢。是的,这也让我困惑。起初,我考虑了预期条件下的or和,但问题中的代码示例让我找到了jasmine matchers。