My directive is responsible for toggling classes on an element, and it's working as expected. However, I seem to be encountering an issue with the jasmine test case for it.
// Code for toggling class
fileSearch.directive('toggleClass', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
element.toggleClass(attrs.toggleClass);
});
}
};
});
Jasmine Test Case:
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');
});
});
I'm getting an error message stating that "undefined is not a constructor" at the line "expect(element).toHaveClass('highlighted');". Can anyone provide some guidance on this? I am relatively new to Angular.