X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=835dde61efafbc099594914c20535fa847a502c9;hb=948753842bd5aeda6ad6e27c269d706675f488d1;hp=533fcef2d0637529ba835ec70a3f55417e0ba3eb;hpb=b3ec8edddd9261eef490f8317144e9c68c888819;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 533fcef..835dde6 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -152,7 +152,7 @@ test("isFunction", function() { var foo = false; test("$('html')", function() { - expect(5); + expect(6); reset(); foo = false; @@ -169,6 +169,8 @@ test("$('html')", function() { var j = $("hi there "); ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" ); + + ok( !$("")[0].selected, "Make sure that options are auto-selected #2050" ); }); test("$('html', context)", function() { @@ -212,10 +214,11 @@ test("get(Number)", function() { }); test("add(String|Element|Array|undefined)", function() { - expect(8); + expect(9); isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" ); + equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" ); var x = $([]).add($("

xxx

")).add($("

xxx

")); ok( x[0].id == "x1", "Check on-the-fly element1" ); @@ -418,7 +421,7 @@ test("css(String|Hash)", function() { }); test("css(String, Object)", function() { - expect(20); + expect(21); ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible'); $('#foo').css('display', 'none'); ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden'); @@ -452,6 +455,10 @@ test("css(String, Object)", function() { var j = $("#nonnodes").contents(); j.css("padding-left", "1px"); equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" ); + + // opera sometimes doesn't update 'display' correctly, see #2037 + $("#t2037")[0].innerHTML = $("#t2037")[0].innerHTML + equals( $("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" ); }); test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () { @@ -467,12 +474,55 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct }); test("width()", function() { - expect(2); + expect(9); + + var $div = $("#nothiddendiv"); + $div.width(30); + equals($div.width(), 30, "Test set to 30 correctly"); + $div.width(-1); // handle negative numbers by ignoring #1599 + equals($div.width(), 30, "Test negative width ignored"); + $div.css("padding", "20px"); + equals($div.width(), 30, "Test padding specified with pixels"); + $div.css("border", "2px solid #fff"); + equals($div.width(), 30, "Test border specified with pixels"); + $div.css("padding", "2em"); + equals($div.width(), 30, "Test padding specified with ems"); + $div.css("border", "1em solid #fff"); + equals($div.width(), 30, "Test border specified with ems"); + $div.css("padding", "2%"); + equals($div.width(), 30, "Test padding specified with percent"); + $div.hide(); + equals($div.width(), 30, "Test hidden div"); + + $div.css({ display: "", border: "", padding: "" }); + + $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" }); + equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding"); + $("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" }); +}); + +test("height()", function() { + expect(8); - $("#nothiddendiv").width(30); - equals($("#nothiddendiv").width(), 30, "Test set to 30 correctly"); - $("#nothiddendiv").width(-1); // handle negative numbers by ignoring #1599 - equals($("#nothiddendiv").width(), 30, "Test negative width ignored"); + var $div = $("#nothiddendiv"); + $div.height(30); + equals($div.height(), 30, "Test set to 30 correctly"); + $div.height(-1); // handle negative numbers by ignoring #1599 + equals($div.height(), 30, "Test negative height ignored"); + $div.css("padding", "20px"); + equals($div.height(), 30, "Test padding specified with pixels"); + $div.css("border", "2px solid #fff"); + equals($div.height(), 30, "Test border specified with pixels"); + $div.css("padding", "2em"); + equals($div.height(), 30, "Test padding specified with ems"); + $div.css("border", "1em solid #fff"); + equals($div.height(), 30, "Test border specified with ems"); + $div.css("padding", "2%"); + equals($div.height(), 30, "Test padding specified with percent"); + $div.hide(); + equals($div.height(), 30, "Test hidden div"); + + $div.css({ display: "", border: "", padding: "", height: "1px" }); }); test("text()", function() { @@ -864,7 +914,7 @@ test("find(String)", function() { }); test("clone()", function() { - expect(4); + expect(6); ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' ); var clone = $('#yahoo').clone(); ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' ); @@ -872,6 +922,16 @@ test("clone()", function() { // using contents will get comments regular, text, and comment nodes var cl = $("#nonnodes").contents().clone(); ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); + + stop(); + $.get("data/dashboard.xml", function (xml) { + var root = $(xml.documentElement).clone(); + $("tab:first", xml).text("origval"); + $("tab:first", root).text("cloneval"); + equals($("tab:first", xml).text(), "origval", "Check original XML node was correctly set"); + equals($("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set"); + start(); + }); }); test("is(String)", function() { @@ -970,11 +1030,12 @@ test("$.extend(Object, Object)", function() { }); test("val()", function() { - expect(3); + expect(4); ok( $("#text1").val() == "Test", "Check for value of input element" ); ok( !$("#text1").val() == "", "Check for value of input element" ); // ticket #1714 this caused a JS error in IE ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" ); + ok( $([]).val() === undefined, "Check an empty jQuery object will return undefined from val" ); }); test("val(String)", function() { @@ -1022,7 +1083,8 @@ test("html(String)", function() { $("#main").html('foo
'); - $("#main").html("