From 597810ebf22e44ab9b91541f7e76c5136fa9e81a Mon Sep 17 00:00:00 2001 From: Josemar Luedke Date: Thu, 30 May 2019 11:50:25 -0700 Subject: [PATCH] [BUGFIX] Fix 'hasAttribute is not a function' when jQuery is disabled --- .../integration/event-dispatcher-test.js | 23 +++++++++++++++++++ .../views/lib/system/event_dispatcher.js | 5 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/@ember/-internals/glimmer/tests/integration/event-dispatcher-test.js b/packages/@ember/-internals/glimmer/tests/integration/event-dispatcher-test.js index d5ffa8e7714..cd564c742c2 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/event-dispatcher-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/event-dispatcher-test.js @@ -555,6 +555,29 @@ if (jQueryDisabled) { assert.ok(receivedEvent, 'click event was triggered'); assert.notOk(receivedEvent.originalEvent, 'event is not a jQuery.Event'); } + + ['@test native event on text node does not throw on hasAttribute [ISSUE #16730]'](assert) { + this.registerComponent('x-foo', { + ComponentClass: Component.extend({ + actions: { + someAction() {}, + }, + }), + template: `test`, + }); + + this.render(`{{x-foo id="outer"}}`); + + let node = this.$('#inner')[0].childNodes[0]; + + runTask(() => { + let event = document.createEvent('HTMLEvents'); + event.initEvent('mousemove', true, true); + node.dispatchEvent(event); + }); + + assert.ok(true); + } } ); } else { diff --git a/packages/@ember/-internals/views/lib/system/event_dispatcher.js b/packages/@ember/-internals/views/lib/system/event_dispatcher.js index 3cb5295b3b4..f000a24c162 100644 --- a/packages/@ember/-internals/views/lib/system/event_dispatcher.js +++ b/packages/@ember/-internals/views/lib/system/event_dispatcher.js @@ -366,7 +366,10 @@ export default EmberObject.extend({ } else if (event.cancelBubble === true) { break; } - } else if (target.hasAttribute('data-ember-action')) { + } else if ( + typeof target.hasAttribute === 'function' && + target.hasAttribute('data-ember-action') + ) { if (actionHandler(target, event) === false) { break; }