I have a directive with the below link function. The setOver and setRating are functions in the directives' controller.
function (scope, iElem) {
return angular.forEach(iElem.children(), function (ul) {
return angular.forEach(ul.children, function (li) {
li.addEventListener('mouseover', function () {
return scope.setOver(parseInt($(li).attr('data-val')));
});
li.addEventListener('mouseout', function () {
return scope.setOver(0);
});
return li.addEventListener('click', function () {
return scope.setRating(parseInt($(li).attr('data-val')), ul);
});
});
});
}
The template of the directive is as below.
<div><ul><li ng-class="{\'glyphicon-star active\':model>0,\'glyphicon-star-empty\':model<=0,\'over\':over>0}" data-val=1>this is a test</li><li ng-class="{\'glyphicon-star active\':model>1,\'glyphicon-star-empty\':model<=1,\'over\':over>1}" data-val=2>this is a test</li></ul></div>
I have the below and it is not working.
element = compile('....')(scope); // abridged to be concise
angular.forEach(element.children(), function (ul) {
angular.forEach(ul.children, function (li) {
if (i === 0) {
var mouseOverEvent = jQuery.Event('mouseover');
$(li).trigger(mouseOverEvent);
console.log(li);
expect($(li).hasClass('over')).toBe(true);
i++;
}
});
});
I want to know how I can simulate the mouseover, mouseout and click events on the li element.