Home How to trigger element.on('mouseleave') in a Uint Test to call my AngularJS function
 I want to call myFunction. Then I want to verify it was called with a Unit Test. Javascript: var self = this; self.myFunction= function myFunction() { // do stuff }; self.onClickChange = function onClickChange() { $('.checkBox').on('mouseleave', function(){ self.myFunction(); }); };  I have tried this test: it('should call myFunction', inject(function ($compile, $rootScope) { spyOn(this.instance, 'onClickChange').and.callThrough(); spyOn(this.instance, 'myFunction').and.callThrough(); this.instance.onClickChange('messageBoard'); var scope =$rootScope.$new(), element =$compile('')(scope); element.triggerHandler('mouseleave'); scope.$digest(); expect(this.instance.myFunction).toHaveBeenCalled(); }));  I have also tried using scope.$broadcast('mouseleave');  And var event = document.createEvent('MouseEvents'); event.initEvent('mouseleave', true, true); \$('.checkBox').dispatchEvent(event);  And this instead of the last line in the previous three lines: document.body.dispatchEvent(event);  How can I get .on('mouseleave') to work and ferify that myFunction has been called?