【发布时间】:2015-01-18 13:25:12
【问题描述】:
我有以下角度指令,当我将鼠标悬停在跨度上时会添加一个工具提示。
angular.module('mainMod')
.directive('toolTip', [function() {
return {
restrict: 'A',
scope: {
theTooltip: '@toolTip'
},
link: function(scope, element, attrs){
element.tooltip({
delay: 0,
showURL: false,
bodyHandler: function() {
return jQuery('<div class="hover">').text(scope.theTooltip);
}
});
}
}
}])
;
<span ng-show="data.tooltip" class="icon" tool-tip="{{data.tooltip}}"></span>
我正在为此指令编写单元测试,atm 我不能使用jasmine-jquery。
我对编写单元测试还很陌生,谁能帮帮我?
给我一些建议或指向一些有用的资源?
任何意见或建议将不胜感激。
我的atm并不多......
describe('Unit testing tooltip', function() {
var $compile;
var $rootScope;
// Load the myApp module, which contains the directive
beforeEach(module('mainMod'));
// Store references to $rootScope and $compile
// so they are available to all tests in this describe block
beforeEach(inject(function(_$compile_, _$rootScope_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
it(' ', function() {
// Compile a piece of HTML containing the directive
FAILS HERE --> var element = $compile("<span class='icon' tool-tip='{{data.tooltip}}'></span>")($rootScope);
$rootScope.$digest();
});
});
失败并显示
消息TypeError: undefined is not a function
我认为这是由我上面指定的行末尾的 ($rootScope) 引起的。
【问题讨论】:
标签: angularjs unit-testing angularjs-directive jasmine