Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .add #1656

Merged
merged 3 commits into from
Jan 9, 2021
Merged
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
10 changes: 2 additions & 8 deletions lib/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,14 +902,8 @@ exports.end = function () {
*/
exports.add = function (other, context) {
var selection = this._make(other, context);
var contents = uniqueSort(selection.get().concat(this.get()));

for (var i = 0; i < contents.length; ++i) {
selection[i] = contents[i];
}
selection.length = contents.length;

return selection;
var contents = uniqueSort(this.get().concat(selection.get()));
return this._make(contents);
};

/**
Expand Down
15 changes: 15 additions & 0 deletions test/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,21 @@ describe('$(...)', function () {
expect($selection[3]).toBe($pear[0]);
});
});

it('modifying nested selections should not impact the parent [#834]', function () {
var apple_pear = $apple.add($pear);

// applies red to apple and pear
apple_pear.addClass('red');

expect($apple.hasClass('red')).toBe(true); // this is true
expect($pear.hasClass('red')).toBe(true); // this is true

// applies green to pear... AND should not affect apple
$pear.addClass('green');
expect($pear.hasClass('green')).toBe(true); //currently this is true
expect($apple.hasClass('green')).toBe(false); // and this should be false!
});
});
});

Expand Down