X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=3a3b42f840f9abb216de544cd5c5deffe21e3998;hb=67d445a703491c90a7d3c46be34bcdceb4d1c896;hp=5d2f5f407ddd38ab0e84c4736c434be12bbb7db1;hpb=0a8f96ac3d37f637ab433c037d4f807e8ef94bbe;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 5d2f5f4..3a3b42f 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -12,7 +12,21 @@ test("Basic requirements", function() { }); test("jQuery()", function() { - expect(8); + expect(12); + + // 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([])" ); + + var obj = jQuery("div") + equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); + + // 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,45 +56,49 @@ 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" ); }); test("selector state", function() { - expect(26); + expect(31); 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" ); - + + 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" ); - + + // Test cloning + 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" ); @@ -88,26 +106,33 @@ 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" ); + + var d = "
"; + equals( + jQuery(d).appendTo(jQuery(d)).selector, + jQuery(d).appendTo(d).selector, + "manipulation methods make same selector for jQuery objects" + ); }); test("browser", function() { @@ -141,7 +166,7 @@ test("browser", function() { }; for (var i in browsers) { var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check - version = v ? v[1] : null; + var version = v ? v[1] : null; equals( version, browsers[i], "Checking UA string" ); } }); @@ -251,23 +276,64 @@ test("isFunction", function() { }); }); -var foo = false; +test("isXMLDoc - HTML", function() { + expect(4); + + ok( !jQuery.isXMLDoc( document ), "HTML document" ); + ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" ); + ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" ); + + var iframe = document.createElement("iframe"); + document.body.appendChild( iframe ); + + try { + var body = jQuery(iframe).contents()[0]; + ok( !jQuery.isXMLDoc( body ), "Iframe body element" ); + } catch(e){ + ok( false, "Iframe body element exception" ); + } + + document.body.removeChild( iframe ); +}); + +if ( !isLocal ) { +test("isXMLDoc - XML", function() { + expect(3); + stop(); + jQuery.get('data/dashboard.xml', function(xml) { + ok( jQuery.isXMLDoc( xml ), "XML document" ); + ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" ); + ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" ); + start(); + }); +}); +} test("jQuery('html')", function() { - expect(6); + expect(13); reset(); - foo = false; - var s = jQuery("")[0]; + jQuery.foo = false; + var s = jQuery("")[0]; ok( s, "Creating a script" ); - ok( !foo, "Make sure the script wasn't executed prematurely" ); - jQuery("body").append(""); - ok( foo, "Executing a scripts contents in the right context" ); + ok( !jQuery.foo, "Make sure the script wasn't executed prematurely" ); + jQuery("body").append(""); + ok( jQuery.foo, "Executing a scripts contents in the right context" ); + + // Test multi-line HTML + var div = jQuery("
\r\nsome text\n

some p

\nmore text\r\n
")[0]; + equals( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." ); + equals( div.firstChild.nodeType, 3, "Text node." ); + equals( div.lastChild.nodeType, 3, "Text node." ); + equals( div.childNodes[1].nodeType, 1, "Paragraph." ); + equals( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." ); reset(); ok( jQuery("")[0], "Creating a link" ); - reset(); + ok( !jQuery("'); - - jQuery("#main").html('foo
'); - - // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959 - jQuery("#main").html("