【发布时间】:2014-05-28 17:44:47
【问题描述】:
我有一个如下指令,我想将其作为我的 jasmine 单元测试的一部分进行介绍,但不确定如何在我的测试用例中获取模板值和链接内的值。这是我第一次尝试对指令进行单元测试。
angular.module('newFrame', ['ngResource'])
.directive('newFrame', [
function () {
function onAdd() {
$log.info('Clicked onAdd()');
}
return {
restrict: 'E',
replace: 'true',
transclude: true,
scope: {
filter: '=',
expand: '='
},
template:
'<div class="voice ">' +
'<section class="module">' +
'<h3>All Frames (00:11) - Summary View</h3>' +
'<button class="btn" ng-disabled="isDisabled" ng-hide="isReadOnly" ng-click="onAdd()">Add a frame</button>' +
'</section>' +
'</div>',
link: function (scope) {
scope.isDisabled = false;
scope.isReadOnly = false;
scope.onAdd = onAdd();
}
};
}
]);
【问题讨论】:
标签: angularjs unit-testing angularjs-directive jasmine karma-jasmine