测试中使用AngularJS茉莉花元素的数量 [英] Test for the number of elements using Jasmine in AngularJS

查看:165
本文介绍了测试中使用AngularJS茉莉花元素的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个端到端的使用茉莉AngularJS测试。我使用量角器来运行测试。我有以下标记

I am writing an end to end test using Jasmine for AngularJS. I am using Protractor to run the test. I have the following markup

<ul class="phone-thumbs">
  <li ng-repeat="img in phone.images">
    <img ng-src="{{img}}">
  </li>
</ul>

和我想测试特定页面实例我有这些图片中的四个。以下是我迄今为止

And I want to test that for a particular page instance I have four of these images. Here's what I have so far

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

问题是,我得到一个错误说

Problem is that I get an error saying

TypeError: Object #<Object> has no method 'length'

我在哪里去了?

推荐答案

这个问题是在的教程AngularJS的8 教程。

下面是我如何解决它。我把计数渲染图像,而不是直接测试中继/模型的不同之路。

Here is how I solved it. I took the different road of counting the images rendered rather than testing the repeater/model directly.

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

这篇关于测试中使用AngularJS茉莉花元素的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆