首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >要求项目中的Angular指令测试

要求项目中的Angular指令测试
EN

Stack Overflow用户
提问于 2014-06-14 02:53:11
回答 1查看 109关注 0票数 1

我正在尝试测试我的指令,但在此之前,我想确保一切都设置正确。我正在尝试测试以下代码,但它不工作。我在我的项目中使用了require,到目前为止,我已经成功地测试了我的控制器。

代码语言:javascript
复制
    define([
  'angular',
  'angular-mocks',
  'Source/modules/common/directive/dynamic-forms/fields/index'
], function () {
  describe('Dynamic fields directive in app.dynamic-form-fields', function () {
    var scope, compile, element;
    beforeEach(
      module('app.dynamic-form-fields'));

    beforeEach(function () {
      inject(function ($rootScope, $compile) {
        element = angular.element('<div class="well span6">' +
          '<h3>Busdriver Albums:</h3>' +
          '<albums ng-repeat="album in albums" title="{{album.title}}">' +
          '</albums></div>');

        scope = $rootScope;

        scope.albums = [
          {
            'title': 'Memoirs of the Elephant Man'
          },
          {
            'title': 'Temporary Forever'
          }
        ];

        $compile(element)(scope);
        scope.$digest();
      });
    });

    it("should have the correct amount of albums in the list", function () {
      var list = element.find('li');
      expect(list.length).toBe(2);
    });
  });

})

输出=预期0为2。

EN

回答 1

Stack Overflow用户

发布于 2014-06-14 03:45:04

我很抱歉问这个愚蠢的问题。在期望值中设置的选择器不正确。

生成正确的html

代码语言:javascript
复制
  <h3>Busdriver Albums:</h3>
<!-- ngRepeat: album in albums -->
<albums ng-repeat="album in albums" title="Memoirs of the Elephant Man" class="ng-scope"></albums><!-- end ngRepeat: album in albums -->
<albums ng-repeat="album in albums" title="Temporary Forever" class="ng-scope"></albums>
<!-- end ngRepeat: album in albums -->

真的很抱歉。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24212130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档