Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Strange behavior of triggerHandler in jqLite #8469

Closed
@meeroslav

Description

@meeroslav

When using input file onchange functionality we can do it directly by binding function to change event:
(angular.element(input)).on("change", function (evt) {
//...use here evt.target.files
});
input.click();

Fun starts when I try to unit test it. Normally triggerHandler passes some dummy data (preventDefault and stopPropagation properties to be exact). In order to test it I need to pass some argument like this:
(angular.element(input)).triggerHandler("change", [{target: {files: fileList}]);

However triggerHandler passes in that case following data to my listenerFunction:
[{preventDefault: noop, stopPropagation: noop },{target: {files: fileList}]. Since actual image data is in second argument, listener will not pick it up.

I think error is in following line in angular.js in triggerHandler definition:
triggerHandler: function (element, eventName, eventData) {
...
eventData = eventData || [];
var event = [{
preventDefault: noop,
stopPropagation: noop
}]
forEach(eventFns, function (fn) {
fn.apply(element, event.concat(eventData));
});
}

which should be:
triggerHandler: function (element, eventName, eventData) {
...
var event = {
preventDefault: noop,
stopPropagation: noop
}
forEach(eventFns, function (fn) {
fn.apply(element, [eventData || event]);
});
}

and the call would then be:
(angular.element(input)).triggerHandler("change", {target: {files: fileList});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions