From 22526c6e19570110631f8f2f352e5bb6749fb8bc Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Fri, 27 Jun 2014 23:43:53 +0300 Subject: [PATCH] feat(jqLite): support isDefaultPrevented for triggerHandler dummies triggerHandler sends dummy events to an element, but although the event includes the preventDefault method, there is no way to see if it was called for the event. This is sometimes important when testing directives that use preventDefault --- src/jqLite.js | 7 ++++++- test/jqLiteSpec.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/jqLite.js b/src/jqLite.js index ef5082ed2233..0cce8f34afd1 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -953,7 +953,12 @@ forEach({ eventData = eventData || []; var event = [{ - preventDefault: noop, + preventDefault: function() { + this.defaultPrevented = true; + }, + isDefaultPrevented: function() { + return this.defaultPrevented === true; + }, stopPropagation: noop }]; diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index cf880aef0382..01767ce2df07 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1690,6 +1690,20 @@ describe('jqLite', function() { data = pokeSpy.mostRecentCall.args[1]; expect(data.hello).toBe("world"); }); + + it('should mark event as prevented if preventDefault is called', function() { + var element = jqLite('poke'), + pokeSpy = jasmine.createSpy('poke'), + event; + + element.on('click', pokeSpy); + element.triggerHandler('click'); + event = pokeSpy.mostRecentCall.args[0]; + + expect(event.isDefaultPrevented()).toBe(false); + event.preventDefault(); + expect(event.isDefaultPrevented()).toBe(true); + }); });