X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=002b130e1c31c732ea8cb719a6a77b0ba07ca1eb;hb=0865b073f81513056f46296cd2a236ab2ca35703;hp=a0e7b1f846661204e78d66a774385ef0f31fa3b8;hpb=1e9593646f5047cfc5b1754b663e59ec9b73dfce;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index a0e7b1f..002b130 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -107,7 +107,7 @@ test("noConflict", function() { }); test("isFunction", function() { - expect(21); + expect(19); // Make sure that false values return false ok( !jQuery.isFunction(), "No Value" ); @@ -145,7 +145,8 @@ test("isFunction", function() { ok( !jQuery.isFunction(obj), "Object Element" ); // IE says this is an object - ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); var nodes = document.body.childNodes; @@ -162,7 +163,8 @@ test("isFunction", function() { document.body.appendChild( input ); // IE says this is an object - ok( jQuery.isFunction(input.focus), "A default function property" ); + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(input.focus), "A default function property" ); document.body.removeChild( input ); @@ -1140,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() { @@ -1174,7 +1188,7 @@ test("val(String/Number)", function() { var scriptorder = 0; test("html(String)", function() { - expect(11); + expect(13); var div = jQuery("#main > div"); div.html("test"); var pass = true; @@ -1196,6 +1210,10 @@ test("html(String)", function() { jQuery("#main select").html(""); equals( jQuery("#main select").val(), "O2", "Selected option correct" ); + var $div = jQuery('
'); + equals( $div.html( 5 ).html(), '5', 'Setting a number as html' ); + equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' ); + stop(); jQuery("#main").html(''); @@ -1229,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"); @@ -1571,13 +1589,18 @@ test("empty()", function() { }); test("slice()", function() { - expect(5); - isSet( jQuery("#ap a").slice(1,2), q("groups"), "slice(1,2)" ); - isSet( jQuery("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" ); - isSet( jQuery("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" ); - isSet( jQuery("#ap a").slice(-1), q("mark"), "slice(-1)" ); + expect(6); + + var $links = jQuery("#ap a"); + + isSet( $links.slice(1,2), q("groups"), "slice(1,2)" ); + isSet( $links.slice(1), q("groups", "anchor1", "mark"), "slice(1)" ); + isSet( $links.slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" ); + isSet( $links.slice(-1), q("mark"), "slice(-1)" ); - isSet( jQuery("#ap a").eq(1), q("groups"), "eq(1)" ); + isSet( $links.eq(1), q("groups"), "eq(1)" ); + + isSet( $links.eq('2'), q("anchor1"), "eq('2')" ); }); test("map()", function() { @@ -1661,7 +1684,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" ); @@ -1685,8 +1708,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" );