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

fix(angular.element): do not break on cleanData() if _data() returns undefined #16642

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ function bindJQuery() {
jqLite.cleanData = function(elems) {
var events;
for (var i = 0, elem; (elem = elems[i]) != null; i++) {
events = jqLite._data(elem).events;
events = (jqLite._data(elem) || {}).events;
if (events && events.$destroy) {
jqLite(elem).triggerHandler('$destroy');
}
Expand Down
6 changes: 6 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ describe('jqLite', function() {
expect(jqLite(c).data('prop')).toBeUndefined();
});

it('should not break on cleanData(), if element has no data', function() {
var selected = jqLite([a, b, c]);
spyOn(jqLite, '_data').and.returnValue(undefined);
expect(function() { jqLite.cleanData(selected); }).not.toThrow();
});


it('should add and remove data on SVGs', function() {
var svg = jqLite('<svg><rect></rect></svg>');
Expand Down