我知道如何使用 jasmine 进行测试,但是如何使用 jasmined based testacular
to test 指令,假设我定义了这样的指令:
angular.module('todoList', [], function () {
}).directive('dt', function ($compile) {
return {
scope: true,
template: '<p ng-click="test()">HaHaHa</p>',
replace: true,
controller: function ($scope) {
$scope.test = function () {
console.warn('click!');
}
},
link: function ($scope, $el, $attr) {
var checkbox = '<input type="checkbox" >';
$el.append($compile(checkbox)($scope));
}
}
})
如何测试dt
元素?
我找到了一些教程并尝试以这种方式编写测试:
describe('My own function', function(){
it('should get called on a click', inject(function($rootScope, $compile) {
element = $compile('<div dt></div>')($rootScope);
$rootScope.$digest();
browserTrigger(element, 'click');
}));
});
但它不起作用