如何测试指令哪个模板在ng-repeat中包含ng-include

时间:2013-08-14 07:30:02

标签: unit-testing angularjs angularjs-directive

我写了一个指令。在模板中,我在ng-repeat中使用了ng-include:

 <div ng-repeat="page in wStepPages" id="step{{$index}}"  data-ng-show="getCurrentStep() == $index" ng-include="page.page" class="slide-frame">
</div>

例如,如果我的page.page = step1.html:

<div>
  <input id="name" ng-model="isolate.name">
</div>

在我的testSpec中:

describe("test_wizard",function () {
var scope,doc,elem,compiled,html;


beforeEach(module('App.wizard','app/partials/step1.html','app/partials/step2.html','app/partials/step3.html','app/partials/step4.html'));
beforeEach(function(){
    html = '<ov-wizard title="OV_WIZARD" step-pages="stepPages" confirm-bt="confirmbt" data="wizardData"></ov-wizard>';
    inject(function($compile, $rootScope){
        scope = $rootScope.$new();

        elem = angular.element(html);
        compiled = $compile(elem);
        compiled(scope);
        scope.$digest();
    })
});

it("do some thing",function(){

expect(elem.find("#name").length).toEqual(1);
});

})

但它返回0项。 任何帮助我!

1 个答案:

答案 0 :(得分:0)

来自docs

  

find() - 仅限于按标记名称

进行查找