0
テンプレート/ templateUrlを使用せずに指示文があります。この指令の単体テストを書くにはどうすればいいですか?以下のコードは私の指示です。angularjsのユニットテストの作成方法ジャスミンの属性型指示子
var app = angular.module('SampleDirective');
app.directive('sampleContent', [function() {
return {
restrict: 'A',
scope: {
content: '@'
},
link: function (scope, element, attrs) {
var eventHandlers = [];
function onContentChanged(value) {
if (value) {
element.html('');
element.append(value);
}
}
function onDestroy() {
angular.forEach(eventHandlers, function (callback) {
callback();
});
element.remove();
}
eventHandlers.push(scope.$watch('content', onContentChanged));
eventHandlers.push(scope.$on("$destroy", onDestroy));
}
};
}]);
誰もが、私は上記のコードのためのユニットテストを書かれている