diff --git a/src/jqLite.js b/src/jqLite.js index 958242cd171d..6809da74dc0b 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -54,7 +54,7 @@ * - [replaceWith()](http://api.jquery.com/replaceWith/) * - [text()](http://api.jquery.com/text/) * - [toggleClass()](http://api.jquery.com/toggleClass/) - * - [triggerHandler()](http://api.jquery.com/triggerHandler/) - Doesn't pass native event objects to handlers. + * - [triggerHandler()](http://api.jquery.com/triggerHandler/) - Passes a dummy event object to handlers. * - [unbind()](http://api.jquery.com/unbind/) - Does not support namespaces * - [val()](http://api.jquery.com/val/) * - [wrap()](http://api.jquery.com/wrap/) @@ -763,9 +763,10 @@ forEach({ triggerHandler: function(element, eventName) { var eventFns = (JQLiteExpandoStore(element, 'events') || {})[eventName]; + var event; forEach(eventFns, function(fn) { - fn.call(element, null); + fn.call(element, {preventDefault: noop}); }); } }, function(fn, name){ diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 089ae78cd591..1ebe6ad48943 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -792,7 +792,7 @@ describe('jqLite', function() { if (msie < 9){ var evnt = document.createEventObject(); evnt.srcElement = element; - evnt.relatedTarget = relatedTarget; + evnt.relatedTarget = relatedTarget; element.fireEvent('on' + type, evnt); return; }; @@ -1153,6 +1153,21 @@ describe('jqLite', function() { expect(clickSpy1).toHaveBeenCalledOnce(); expect(clickSpy2).toHaveBeenCalledOnce(); }); + + it('should pass in a dummy event', function() { + // we need the event to have at least preventDefault because angular will call it on + // all anchors with no href automatically + + var element = jqLite('poke'), + pokeSpy = jasmine.createSpy('poke'), + event; + + element.bind('click', pokeSpy); + + element.triggerHandler('click'); + event = pokeSpy.mostRecentCall.args[0]; + expect(event.preventDefault).toBeDefined(); + }); });