使用AngularJS中的Jasmine测试元素数量

我正在使用Jasmine for AngularJS编写端到端测试。 我正在使用Protractor来运行测试。 我有以下标记

我想测试一下,对于特定的页面实例,我有四个这样的图像。 这是我到目前为止所拥有的

 describe('Phone detail view', function() { beforeEach(function() { browser.get('app/index.html#/phones/nexus-s'); }); it('should display four thumbnails on the nexus-s page', function() { expect(element(by.css('.phone-thumbs li img')).length()).toBe(4); }); }); 

问题是我得到一个错误说

 TypeError: Object # has no method 'length' 

我哪里错了?

这个问题是AngularJS教程的教程8中的实验部分的一部分。

这是我解决它的方式。 我采用了不同的方法来计算渲染的图像,而不是直接测试转发器/模型。

 it('should display four thumbnails of the nexus-s', function() { var imgsCount = element.all(by.css('.phone-thumbs li img')).count(); expect(imgsCount).toBe(4); }); 

对于任何需要了解这一点的人。 这是我如何做到的。

 it('should display four thumbnails on the nexus-s page', function() { var images = element.all(by.repeater('img in phone.images')).count(); expect(images).toBe(4); });