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

fix(jqLite): clone wrapNode in jqlite/wrap #4194

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/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ forEach({
},

wrap: function(element, wrapNode) {
wrapNode = jqLite(wrapNode)[0];
wrapNode = jqLite(wrapNode).eq(0).clone()[0];
var parent = element.parentNode;
if (parent) {
parent.replaceChild(wrapNode, element);
Expand Down
9 changes: 9 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,15 @@ describe('jqLite', function() {
text.wrap("<span>");
expect(text.parent().text()).toEqual('A<a>B</a>C');
});
it('should clone elements to be wrapped around target', function () {
var root = jqLite('<div class="sigil"></div>');
var span = jqLite('<span>A</span>');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it might be good to check if it behaves sane when wrapping multiple elements.

jqLite(document.body).append(root);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Couldn't you use any other wrapper for root that is not actually in the DOM?


span.wrap(root);
expect(root.text()).toBe('');
expect(span.parent().hasClass('sigil')).toBeTruthy();
});
});


Expand Down