我对我的指令进行了单元测试:
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);
})
如果我更改“scope = $rootScope.$new();”,与 DOM 交互的结果会引发错误 到“范围 = $rootScope;” 他们会正常工作的!
我想测试一下$destroy()
。因为$rootScope
不能调用$destroy()
错误记录在这里!