我在我的应用程序中为指令编写测试用例。请参阅下面的代码。
describe('Note component', function () {
var $rootScope, $compile, $controller;
beforeEach(module('templates'));
beforeEach(module('home'));
beforeEach(module('note'));
beforeEach(inject(function (_$compile_, _$rootScope_, _$log_, _$window_, _$controller_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$log = _$log_;
$window = _$window_;
$controller = _$controller_;
elHome = angular.element("<home-component></home-component>")
$compile(elHome)($rootScope.$new())
elNote = angular.element("<note-component></note-component>")
$compile(elNote)($rootScope.$new())
$rootScope.$digest()
noteController = elNote.controller("noteComponent")
homeController = elHome.controller("homeComponent")
notescope = elNote.isolateScope() || elNote.scope()
homescope = elHome.isolateScope() || elHome.scope()
}));
it('should save note', function () {
notescope.saveNote();
expect($log.debug.logs[0]).toEqual(['Saving note started']);
expect($log.debug.logs[1]).toEqual(['Note saved successfully']);
});
it('should delete note', function () {
notescope.deleteNote();
console.log($log.debug.logs)
});
});
这是返回错误
Argument 'fn' is not a function, got noteController
如果删除it
中的任何一个,它就可以正常工作。意味着,如果要么保存笔记,要么删除笔记&#39;被删除,不会有任何错误。
为什么会这样?