X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2FcoreTest.js;h=db47856095e3a2f2ce98af219b3b24c083e7f2bb;hb=f96bf1041553775a94c1034c97e253e350217173;hp=bb51acbea85c952034a9f9ea15d613f89d413210;hpb=53dc6afc310aa0e5df094304996ef605d4dbbd58;p=jquery.git diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index bb51acb..db47856 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -12,7 +12,7 @@ test("Basic requirements", function() { }); test("$()", function() { - expect(2); + expect(5); var main = $("#main"); isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); @@ -29,6 +29,13 @@ test("$()", function() { pass = false; } ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ + + var code = $(""); + equals( code.length, 1, "Correct number of elements generated for code" ); + var img = $(""); + equals( img.length, 1, "Correct number of elements generated for img" ); + var div = $("

"); + equals( div.length, 4, "Correct number of elements generated for div hr code b" ); }); test("isFunction", function() { @@ -232,7 +239,7 @@ test("attr(Hash)", function() { }); test("attr(String, Object)", function() { - expect(8); + expect(12); var div = $("div"); div.attr("foo", "bar"); var pass = true; @@ -255,6 +262,28 @@ test("attr(String, Object)", function() { ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' ); $("#name").attr('maxlength', '5'); ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' ); + + reset(); + + var type = $("#check2").attr('type'); + var thrown = false; + try { + $("#check2").attr('type','hidden'); + } catch(e) { + thrown = true; + } + ok( thrown, "Exception thrown when trying to change type property" ); + equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" ); + + var check = document.createElement("input"); + var thrown = true; + try { + $(check).attr('type','checkbox'); + } catch(e) { + thrown = false; + } + ok( thrown, "Exception thrown when trying to change type property" ); + equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" ); }); test("attr(String, Object) - Loaded via XML document", function() { @@ -807,7 +836,7 @@ test("html(String)", function() { test("filter()", function() { expect(4); - isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); + isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" ); @@ -820,12 +849,20 @@ test("not()", function() { isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); }); +test("andSelf()", function() { + expect(4); + isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" ); + isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" ); + isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" ); + isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" ); +}); + test("siblings([String])", function() { expect(5); isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); - isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "floatTest"), "Check for multiple filters" ); + isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" ); isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" ); });