我正在使用 Jasmine 为 AngularJS 编写端到端测试。我正在使用 Protractor 来运行测试。我有以下标记
<ul class="phone-thumbs">
<li ng-repeat="img in phone.images">
<img ng-src="{{img}}">
</li>
</ul>
而且我想针对一个特定的页面实例测试我有四个这样的图像。这是我目前所拥有的
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 #<Object> has no method 'length'
我哪里错了?
最佳答案
这个问题是 tutorial 8 中实验部分的一部分AngularJS 教程。
我是这样解决的。我采取了不同的方式计算渲染的图像,而不是直接测试中继器/模型。
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);
});
关于javascript - 在 AngularJS 中使用 Jasmine 测试元素数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23583408/