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

Testing element count inside an ng-repeat with 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);

它位于 Jasmine 2.0 文档中,here。 试试下面的代码:

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);