jquery core: Closes #1681. jQuery.fn.toggleClass can accept a boolean argument indica...
[jquery.git] / test / unit / core.js
index 536e58c..5d2f5f4 100644 (file)
@@ -451,7 +451,7 @@ test("attr(Hash)", function() {
 });
 
 test("attr(String, Object)", function() {
-       expect(17);
+       expect(19);
        var div = jQuery("div").attr("foo", "bar");
                fail = false;
        for ( var i = 0; i < div.size(); i++ ) {
@@ -515,6 +515,16 @@ test("attr(String, Object)", function() {
        }
        ok( thrown, "Exception thrown when trying to change type property" );
        equals( "checkbox", jQuery(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
+       
+       var check = jQuery("<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" );
 });
 
 if ( !isLocal ) {
@@ -1138,6 +1148,23 @@ test("is(String)", function() {
        ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
 });
 
+test("jQuery.merge()", function() {
+       expect(6);
+               
+       var parse = jQuery.merge;
+       
+       same( parse([],[]), [], "Empty arrays" );
+       
+       same( parse([1],[2]), [1,2], "Basic" );
+       same( parse([1,2],[3,4]), [1,2,3,4], "Basic" );
+       
+       same( parse([1,2],[]), [1,2], "Second empty" );
+       same( parse([],[1,2]), [1,2], "First empty" );  
+       
+       // Fixed at [5998], #3641
+       same( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)");
+});
+
 test("jQuery.extend(Object, Object)", function() {
        expect(20);
 
@@ -1309,6 +1336,14 @@ test("filter()", function() {
        equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
 });
 
+test("closest()", function() {
+       expect(4);
+       isSet( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
+       isSet( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
+       isSet( jQuery("body").closest("div").get(), [], "closest(div)" );
+       isSet( jQuery("#main").closest("span,#html").get(), q("html"), "closest(span,#html)" );
+});
+
 test("not()", function() {
        expect(8);
        equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
@@ -1458,13 +1493,20 @@ test("removeClass(String) - simple", function() {
 });
 
 test("toggleClass(String)", function() {
-       expect(3);
+       expect(6);\r
        var e = jQuery("#firstp");
        ok( !e.is(".test"), "Assert class not present" );
        e.toggleClass("test");
        ok( e.is(".test"), "Assert class present" );
        e.toggleClass("test");
        ok( !e.is(".test"), "Assert class not present" );
+
+       e.toggleClass("test", false);\r
+       ok( !e.is(".test"), "Assert class not present" );\r
+       e.toggleClass("test", true);\r
+       ok( e.is(".test"), "Assert class present" );\r
+       e.toggleClass("test", false);\r
+       ok( !e.is(".test"), "Assert class not present" );\r
 });
 
 test("removeAttr(String", function() {