不能在测试指令中使用$ rootScope。$ new()

时间:2013-10-01 09:20:52

标签: javascript unit-testing angularjs angularjs-directive

我对我的指令进行了单元测试:

describe('Directive: ov-tabs', function() {
  var $compile, scope,subScope, element, template, doc,timeout,window;
  beforeEach(module('ngnms.ui.tabs','layout.html'));
  beforeEach(inject(function(_$compile_, $rootScope,$templateCache, $timeout,$document, $window) {
    template = $templateCache.get('layout.html');
    $templateCache.put('template/tab-layout.html', template);
    $compile = _$compile_;
    timeout = $timeout;
    window = angular.element($window);
    doc = $document;
    scope = $rootScope.$new();

    var html =
            '<ov-tabset ov-tabs="items" on-tab-selected="tabSelectCallback" on-tab-closed="tabClosedCallback"></ov-tabset>';

    element = angular.element(html);
    $(element).appendTo($('body'));
    //------------------------------------------init scope
          //add 12 items to scope
    //-------------------------------------------end init scope
    $compile(element)(scope);
    scope.$digest();

  }));
it('some thing true',function(){});
   var lis = element.find('li');
   expect(lis.length).toEqual(12);
})

与DOM交互的结果抛出错误 如果我改变“scope = $ rootScope。$ new();” to“scope = $ rootScope;”他们会工作得很好!

我想测试$destroy()。因为$rootScope无法调用$destroy()

错误登录! enter image description here

0 个答案:

没有答案