X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=ade34152757f8a362c75a76f0738451f4c9f2369;hb=c41fab1eb099cd284b65c0d37431adfb38f4106a;hp=6da62be9ad8385aecd43ac63ac0bfe898d1e6aa2;hpb=ce90accc58d213fcf567ab2ca464ee9164601dc4;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 6da62be..ade3415 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -12,8 +12,19 @@ test("Basic requirements", function() { }); test("jQuery()", function() { - expect(8); + expect(11); + // Basic constructor's behavior + + equals( jQuery().length, 1, "jQuery() === jQuery(document)" ); + equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); + equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); + equals( jQuery("").length, 0, "jQuery('') === jQuery([])" ); + + // can actually yield more than one, when iframes are included, the window is an array as well + equals( 1, jQuery(window).length, "Correct number of elements generated for jQuery(window)" ); + + var main = jQuery("#main"); isSet( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); @@ -42,11 +53,6 @@ test("jQuery()", function() { var div = jQuery("

"); equals( div.length, 4, "Correct number of elements generated for div hr code b" ); - // can actually yield more than one, when iframes are included, the window is an array as well - equals( jQuery(window).length, 1, "Correct number of elements generated for window" ); - - equals( jQuery(document).length, 1, "Correct number of elements generated for document" ); - equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" ); @@ -56,19 +62,19 @@ test("selector state", function() { expect(30); var test; - - test = jQuery(); + + test = jQuery(undefined); equals( test.selector, "", "Empty jQuery Selector" ); - equals( test.context, document, "Empty jQuery Context" ); - + equals( test.context, undefined, "Empty jQuery Context" ); + test = jQuery(document); equals( test.selector, "", "Document Selector" ); equals( test.context, document, "Document Context" ); - + test = jQuery(document.body); equals( test.selector, "", "Body Selector" ); equals( test.context, document.body, "Body Context" ); - + test = jQuery("#main"); equals( test.selector, "#main", "#main Selector" ); equals( test.context, document, "#main Context" ); @@ -76,11 +82,11 @@ test("selector state", function() { test = jQuery("#notfoundnono"); equals( test.selector, "#notfoundnono", "#notfoundnono Selector" ); equals( test.context, document, "#notfoundnono Context" ); - + test = jQuery("#main", document); equals( test.selector, "#main", "#main Selector" ); equals( test.context, document, "#main Context" ); - + test = jQuery("#main", document.body); equals( test.selector, "#main", "#main Selector" ); equals( test.context, document.body, "#main Context" ); @@ -89,7 +95,7 @@ test("selector state", function() { test = jQuery(test); equals( test.selector, "#main", "#main Selector" ); equals( test.context, document.body, "#main Context" ); - + test = jQuery(document.body).find("#main"); equals( test.selector, "#main", "#main find Selector" ); equals( test.context, document.body, "#main find Context" ); @@ -97,23 +103,23 @@ test("selector state", function() { test = jQuery("#main").filter("div"); equals( test.selector, "#main.filter(div)", "#main filter Selector" ); equals( test.context, document, "#main filter Context" ); - + test = jQuery("#main").not("div"); equals( test.selector, "#main.not(div)", "#main not Selector" ); equals( test.context, document, "#main not Context" ); - + test = jQuery("#main").filter("div").not("div"); equals( test.selector, "#main.filter(div).not(div)", "#main filter, not Selector" ); equals( test.context, document, "#main filter, not Context" ); - + test = jQuery("#main").filter("div").not("div").end(); equals( test.selector, "#main.filter(div)", "#main filter, not, end Selector" ); equals( test.context, document, "#main filter, not, end Context" ); - + test = jQuery("#main").parent("body"); equals( test.selector, "#main.parent(body)", "#main parent Selector" ); equals( test.context, document, "#main parent Context" ); - + test = jQuery("#main").eq(0); equals( test.selector, "#main.slice(0,1)", "#main eq Selector" ); equals( test.context, document, "#main eq Context" ); @@ -366,12 +372,13 @@ test("each(Function)", function() { ok( pass, "Execute a function, Relative" ); }); -test("index(Object)", function() { - expect(10); +test("index(Object|String|undefined)", function() { + expect(16); var elements = jQuery([window, document]), inputElements = jQuery('#radio1,#radio2,#check1,#check2'); + // Passing a node equals( elements.index(window), 0, "Check for index of elements" ); equals( elements.index(document), 1, "Check for index of elements" ); equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" ); @@ -381,890 +388,34 @@ test("index(Object)", function() { equals( inputElements.index(window), -1, "Check for not found index" ); equals( inputElements.index(document), -1, "Check for not found index" ); + // Passing a jQuery object // enabled since [5500] equals( elements.index( elements ), 0, "Pass in a jQuery object" ); equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" ); -}); - -test("attr(String)", function() { - expect(27); - equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' ); - equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' ); - equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' ); - equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' ); - equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' ); - equals( jQuery('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' ); - equals( jQuery('#google').attr('title'), "Google!", 'Check for title attribute' ); - equals( jQuery('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' ); - equals( jQuery('#en').attr('lang'), "en", 'Check for lang attribute' ); - equals( jQuery('#simon').attr('class'), "blog link", 'Check for class attribute' ); - equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' ); - equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' ); - ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); - equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' ); - equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' ); - equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' ); - equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' ); - equals( jQuery('#foo').attr('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' ); - equals( jQuery('#foo').attr('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' ); - - jQuery('').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path - equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' ); - - equals( jQuery("