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

Commit 63414b9

Browse files
joaomsapetebacondarwin
authored andcommitted
fix(jqLite): prepend array in correct order
Match jQuery behavior when prepending array into empty element
1 parent 5f24bb0 commit 63414b9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/jqLite.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,7 @@ forEach({
689689
if (element.nodeType === 1) {
690690
var index = element.firstChild;
691691
forEach(new JQLite(node), function(child){
692-
if (index) {
693-
element.insertBefore(child, index);
694-
} else {
695-
element.appendChild(child);
696-
index = child;
697-
}
692+
element.insertBefore(child, index);
698693
});
699694
}
700695
},

test/jqLiteSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,18 @@ describe('jqLite', function() {
10231023
expect(root.prepend('abc')).toEqual(root);
10241024
expect(root.html().toLowerCase()).toEqual('abctext');
10251025
});
1026+
it('should prepend array to empty in the right order', function() {
1027+
var root = jqLite('<div>');
1028+
expect(root.prepend([a, b, c])).toBe(root);
1029+
expect(sortedHtml(root)).
1030+
toBe('<div><div>A</div><div>B</div><div>C</div></div>');
1031+
});
1032+
it('should prepend array to content in the right order', function() {
1033+
var root = jqLite('<div>text</div>');
1034+
expect(root.prepend([a, b, c])).toBe(root);
1035+
expect(sortedHtml(root)).
1036+
toBe('<div><div>A</div><div>B</div><div>C</div>text</div>');
1037+
});
10261038
});
10271039

10281040

0 commit comments

Comments
 (0)