我对我的指令进行了单元测试:
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()
错误登录!