admin管理员组

文章数量:1317565

I want to test that my ng-repeat generates more than 1 element.

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

How can I do it? I can't find in the docs...
Is there something like this?

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

I want to test that my ng-repeat generates more than 1 element.

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

How can I do it? I can't find in the docs...
Is there something like this?

expect(element.all(by.repeater('topic in topics')).count()).toBeMoreThan(1);
Share Improve this question asked Apr 24, 2015 at 9:21 ProGMProGM 7,1084 gold badges35 silver badges54 bronze badges 1
  • Why can't you count topics length? – YD1m Commented Apr 24, 2015 at 9:31
Add a ment  | 

2 Answers 2

Reset to default 5

It is located in the Jasmine 2.0 docs, here. Try the following code:

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

While the accepted answer works, it can now be done a lot easier. You can just do:

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

本文标签: javascriptTesting element count inside an ngrepeat with protractorStack Overflow