X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=686899efec9f236c24ebe7ae3f0bef425f2e0f8b;hb=475f89b6519c95f730ed04cd3dd715f582873e4d;hp=864f77abc0cca20d5f5a7e9bab7a44836167dd7d;hpb=69212c501f8875b4650847053cc41eaa470e5848;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 864f77a..686899e 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1142,11 +1142,23 @@ test("jQuery.extend(Object, Object)", function() { }); test("val()", function() { - expect(3); + expect(8); + equals( jQuery("#text1").val(), "Test", "Check for value of input element" ); // ticket #1714 this caused a JS error in IE equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" ); ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" ); + + equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' ); + + isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' ); + + equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' ); + + equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' ); + + equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' ); + }); test("val(String/Number)", function() { @@ -1235,7 +1247,7 @@ test("not()", function() { isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); - isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')"); + isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')"); var selects = jQuery("#form select"); isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element"); @@ -1349,25 +1361,24 @@ test("addClass(String)", function() { test("removeClass(String) - simple", function() { expect(4); - var div = jQuery("div").addClass("test").removeClass("test"), - pass = true; - for ( var i = 0; i < div.size(); i++ ) { - if ( div.get(i).className.indexOf("test") != -1 ) pass = false; - } - ok( pass, "Remove Class" ); + + var $divs = jQuery('div'); + + $divs.addClass("test").removeClass("test"); + + ok( !$divs.is('.test'), "Remove Class" ); reset(); - var div = jQuery("div").addClass("test").addClass("foo").addClass("bar"); - div.removeClass("test").removeClass("bar").removeClass("foo"); - var pass = true; - for ( var i = 0; i < div.size(); i++ ) { - if ( div.get(i).className.match(/test|bar|foo/) ) pass = false; - } - ok( pass, "Remove multiple classes" ); + + $divs.addClass("test").addClass("foo").addClass("bar"); + $divs.removeClass("test").removeClass("bar").removeClass("foo"); + + ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" ); reset(); - var div = jQuery("div:eq(0)").addClass("test").removeClass(""); - ok( div.is('.test'), "Empty string passed to removeClass" ); + + $divs.eq(0).addClass("test").removeClass(""); + ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" ); // using contents will get regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); @@ -1672,7 +1683,7 @@ test("contents()", function() { }); test("jQuery.makeArray", function(){ - expect(15); + expect(14); equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" ); @@ -1696,8 +1707,11 @@ test("jQuery.makeArray", function(){ ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" ); - //function, is tricky as it has length - equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); + // function, is tricky as it has length + // NOTE: Due to the conflict with Scriptaculous (http://dev.jquery.com/ticket/3248) + // We remove support for functions since jQuery 1.3 + //equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); + //window, also has length equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );