Added support for the new .andSelf() method. This method combines the previous two...
[jquery.git] / src / jquery / coreTest.js
index bb51acb..d0fc9d2 100644 (file)
@@ -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 = $("<code/>");
+       equals( code.length, 1, "Correct number of elements generated for code" );
+       var img = $("<img/>");
+       equals( img.length, 1, "Correct number of elements generated for img" );
+       var div = $("<div/><hr/><code/><b/>");
+       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() {
@@ -820,6 +849,14 @@ 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" );