Fixes #8129. Fix cloning multiple selected options in IE8.
[jquery.git] / test / unit / manipulation.js
index a68c214..1313783 100644 (file)
@@ -880,7 +880,20 @@ test("jQuery.clone() (#8017)", function() {
        var main = jQuery("#main")[0],
                        clone = jQuery.clone( main );
 
-       equals( main.children.length, clone.children.length, "Simple child length to ensure a large dom tree copies correctly" );
+       equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
+});
+
+test("clone() (#8070)", function () {
+       expect(2);
+
+       jQuery('<select class="test8070"></select><select class="test8070"></select>').appendTo('#main');
+       var selects = jQuery('.test8070');
+       selects.append('<OPTION>1</OPTION><OPTION>2</OPTION>');
+
+       equals( selects[0].childNodes.length, 2, "First select got two nodes" );
+       equals( selects[1].childNodes.length, 2, "Second select got two nodes" );
+
+       selects.remove();
 });
 
 test("clone()", function() {
@@ -940,6 +953,17 @@ test("clone()", function() {
        div.remove();
        clone.remove();
 
+       var divEvt = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
+               ok( false, "Bound event still exists after .clone()." );
+       }),
+               cloneEvt = divEvt.clone();
+
+       // Make sure that doing .clone() doesn't clone events
+       cloneEvt.trigger("click");
+
+       cloneEvt.remove();
+       divEvt.remove();
+
        // this is technically an invalid object, but because of the special
        // classid instantiation it is the only kind that IE has trouble with,
        // so let's test with it too.
@@ -982,7 +1006,7 @@ test("clone()", function() {
 
 test("clone(form element) (Bug #3879, #6655)", function() {
        expect(6);
-       element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
+       var element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
 
        equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
 
@@ -1002,6 +1026,14 @@ test("clone(form element) (Bug #3879, #6655)", function() {
        equals( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
 });
 
+test("clone(multiple selected options) (Bug #8129)", function() {
+       expect(1);
+       var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>");
+
+       equals( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" );
+
+});
+
 if (!isLocal) {
 test("clone() on XML nodes", function() {
        expect(2);