My Directive Link function is given below -
link:function(scope,elem,attr){
$(document).on("click",function(event){
var target = $(event.target);
if(target.is('.detailBox') || target.closest('.detailBox').length){
return;
}
scope.$emit('closeDetailBox');
scope.$apply();
});
}
And my jasmine TC for testing the emit is given below -
it('Some other box click', function () {
spyOn($rootScope, '$emit');
var theboxelement = '<button class="thebox"></button>';
var thebox = $(theboxelement);
$('body').append(thebox);
var spyEvent = spyOnEvent('.thebox', 'click');
thebox.trigger("click");
expect($rootScope.$emit).toHaveBeenCalledWith('closeDetailBox',theboxelement);
thebox.remove();
});
The emit event should have been triggered and caught, but it was never triggered. I get the error - "Expected spy $emit to have been called with [ 'closeDetailBox', '' ] but it was never called."
I have been dealing with this issue since 2 days, could not get the fix, pls help!