Javascript 使用量角器在ng重复中测试元素计数
我想测试我的Javascript 使用量角器在ng重复中测试元素计数,javascript,angularjs,protractor,Javascript,Angularjs,Protractor,我想测试我的ng repeat是否生成多个元素 <div ng-repeat="topic in topics"> <div class="topic-name">{{topic.name}}</div> </div> 它位于Jasmine 2.0文档中。 请尝试以下代码: var count = element.all(by.repeater('topic in topics')); count.then(function(result){
ng repeat
是否生成多个元素
<div ng-repeat="topic in topics">
<div class="topic-name">{{topic.name}}</div>
</div>
它位于Jasmine 2.0文档中。 请尝试以下代码:
var count = element.all(by.repeater('topic in topics'));
count.then(function(result){
expect(result.length).toBeGreaterThan(1);
});
虽然被接受的答案可行,但现在可以做得容易得多。 您只需执行以下操作:
expect(element.all(by.repeater('topic in topics')).count()).toBeGreaterThan(1);
为什么你不能计算
主题长度?这不会出错吗?element.all返回一个承诺,该承诺没有length
属性。@Aaron我相信你是正确的,我已经更新了答案以正确解决每个承诺。对我来说,它还与:expect(element.all(by.repeater('topics in topics').count()).toBeGreaterThan(1)
expect(element.all(by.repeater('topic in topics')).count()).toBeGreaterThan(1);