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

Commit fd87eb0

Browse files
joaomsaIgorMinar
authored andcommitted
fix(jqLite): prepend array in correct order
Match jQuery behavior when prepending array into empty element
1 parent 3ffddad commit fd87eb0

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
@@ -715,12 +715,7 @@ forEach({
715715
if (element.nodeType === 1) {
716716
var index = element.firstChild;
717717
forEach(new JQLite(node), function(child){
718-
if (index) {
719-
element.insertBefore(child, index);
720-
} else {
721-
element.appendChild(child);
722-
index = child;
723-
}
718+
element.insertBefore(child, index);
724719
});
725720
}
726721
},

test/jqLiteSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,18 @@ describe('jqLite', function() {
10751075
expect(root.prepend('abc')).toEqual(root);
10761076
expect(root.html().toLowerCase()).toEqual('abctext');
10771077
});
1078+
it('should prepend array to empty in the right order', function() {
1079+
var root = jqLite('<div>');
1080+
expect(root.prepend([a, b, c])).toBe(root);
1081+
expect(sortedHtml(root)).
1082+
toBe('<div><div>A</div><div>B</div><div>C</div></div>');
1083+
});
1084+
it('should prepend array to content in the right order', function() {
1085+
var root = jqLite('<div>text</div>');
1086+
expect(root.prepend([a, b, c])).toBe(root);
1087+
expect(sortedHtml(root)).
1088+
toBe('<div><div>A</div><div>B</div><div>C</div>text</div>');
1089+
});
10781090
});
10791091

10801092

0 commit comments

Comments
 (0)