I know how to use jasmine to do test, but how to use the jasmined based testacular to test directive, suppose I have defined a directive like this:
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));
}
}
})
how can I test the dt element?
I have find some tutorial and try to write the test in this way:
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');
}));
});
but it doesn't work