【发布时间】:2017-05-21 17:07:30
【问题描述】:
我有一个指令,基本上是在元素上切换类。它工作正常。但是它的 jasmine 测试用例有问题。
//toggling class
fileSearch.directive('toggleClass', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
element.toggleClass(attrs.toggleClass);
});
}
};
});
Jasmine 测试用例:
describe(
'testing toggle-class directive',
function() {
var $compile, $rootScope;
beforeEach(module('myApp'));
beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
it('should set highlight class on report title',
function() {
var element = $compile("<div toggleclass='highlighted'</div>")($rootScope);
element.click();
expect(element).toHaveClass('highlighted');
});
});
它的抛出错误是在“expect(element).toHaveClass('highlighted');”行说 undefined is not a constructor 你能指导我吗?我对 Angular 有点陌生。
【问题讨论】:
标签: javascript angularjs karma-jasmine