使用量角器测试ng-repeat内的元素计数

时间:2015-04-24 09:21:41

标签: javascript angularjs protractor

我想测试我的ng-repeat生成的元素超过1个。

<div ng-repeat="topic in topics">
  <div class="topic-name">{{topic.name}}</div>
</div>

我该怎么办?我在文档中找不到...
有这样的事吗?

expect(element.all(by.repeater('topic in topics')).count()).toBeMoreThan(1);

2 个答案:

答案 0 :(得分:5)

它位于Jasmine 2.0文档中,here。 请尝试以下代码:

var count = element.all(by.repeater('topic in topics'));
count.then(function(result){
    expect(result.length).toBeGreaterThan(1);
});

答案 1 :(得分:4)

虽然接受的答案有效,但现在可以轻松完成。 你可以这样做:

expect(element.all(by.repeater('topic in topics')).count()).toBeGreaterThan(1);