From 72a283bfccce8a5d0af967b0450a67830c3dfa25 Mon Sep 17 00:00:00 2001 From: Teo Dragovic Date: Fri, 28 Feb 2020 09:28:26 +0100 Subject: [PATCH 1/2] Add isDefaultPrevented fn to event --- compat/src/render.js | 1 + compat/test/browser/events.test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/compat/src/render.js b/compat/src/render.js index 96be3a3d8d..7d5106dd1e 100644 --- a/compat/src/render.js +++ b/compat/src/render.js @@ -51,6 +51,7 @@ let oldEventHook = options.event; options.event = e => { if (oldEventHook) e = oldEventHook(e); e.persist = () => {}; + e.isDefaultPrevented = () => e.defaultPrevented; return (e.nativeEvent = e); }; diff --git a/compat/test/browser/events.test.js b/compat/test/browser/events.test.js index 0dd356e90e..ba64808422 100644 --- a/compat/test/browser/events.test.js +++ b/compat/test/browser/events.test.js @@ -36,6 +36,7 @@ describe('preact/compat events', () => { const event = spy.args[0][0]; expect(event).to.haveOwnProperty('persist'); expect(event).to.haveOwnProperty('nativeEvent'); + expect(event).to.haveOwnProperty('isDefaultPrevented'); expect(typeof event.persist).to.equal('function'); expect(() => event.persist()).to.not.throw(); From 4be97ce740a5a36e6a86e398612c0dbfc19b0990 Mon Sep 17 00:00:00 2001 From: Teo Dragovic Date: Fri, 28 Feb 2020 09:39:45 +0100 Subject: [PATCH 2/2] Expand test coverage --- compat/test/browser/events.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compat/test/browser/events.test.js b/compat/test/browser/events.test.js index ba64808422..a4e68ad5fd 100644 --- a/compat/test/browser/events.test.js +++ b/compat/test/browser/events.test.js @@ -38,8 +38,10 @@ describe('preact/compat events', () => { expect(event).to.haveOwnProperty('nativeEvent'); expect(event).to.haveOwnProperty('isDefaultPrevented'); expect(typeof event.persist).to.equal('function'); + expect(typeof event.isDefaultPrevented).to.equal('function'); expect(() => event.persist()).to.not.throw(); + expect(() => event.isDefaultPrevented()).to.not.throw(); }); it('should normalize ondoubleclick event', () => {