diff --git a/lib/utils.js b/lib/utils.js index 6b48cb8c..2e12ef1c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -239,7 +239,7 @@ define( Object.keys(rules).forEach(function(selector) { if (!e.isPropagationStopped() && (parent = target.closest(selector)).length) { data = data || {}; - data.el = parent[0]; + e.currentTarget = data.el = parent[0]; return rules[selector].apply(this, [e, data]); } }, this); diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 6e15e383..368424ba 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -255,12 +255,21 @@ define(['lib/component', 'lib/utils', 'lib/debug'], function (defineComponent, u $(document.body).trigger('click', myData); - myData.el = document.body; - var callbackArgs = spy.mostRecentCall.args; - expect(spy).toHaveBeenCalledWith(jasmine.any($.Event), myData); + expect(callbackArgs[1].el).toBe(document.body); + }); + + it('should pass the correct currentTarget', function () { + var instance = (new Component).initialize(document, {'bodySelector': 'body'}); + + instance.on('click', { + bodySelector: function (event) { + expect(event.currentTarget).toBe(document.body); + } + }); + $(window.div).trigger('click'); }); it('makes "this" in delegated function references be the component instance', function () {