X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=3a3b42f840f9abb216de544cd5c5deffe21e3998;hb=67d445a703491c90a7d3c46be34bcdceb4d1c896;hp=347864eaf6228a28a5efa5b6541299d6a0435ea1;hpb=6b912beb7b7ba3147112b8291ba3d3deb888bdba;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 347864e..3a3b42f 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -12,7 +12,7 @@ test("Basic requirements", function() { }); test("jQuery()", function() { - expect(11); + expect(12); // Basic constructor's behavior @@ -21,6 +21,9 @@ test("jQuery()", function() { 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)" ); @@ -59,7 +62,7 @@ test("jQuery()", function() { }); test("selector state", function() { - expect(30); + expect(31); var test; @@ -123,6 +126,13 @@ test("selector state", function() { 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() { @@ -266,8 +276,41 @@ test("isFunction", function() { }); }); +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(8); + expect(13); reset(); jQuery.foo = false; @@ -277,6 +320,14 @@ test("jQuery('html')", function() { 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" ); @@ -293,7 +344,7 @@ test("jQuery('html')", function() { test("jQuery('html', context)", function() { expect(1); - var $div = jQuery("
"); + var $div = jQuery("
")[0]; var $span = jQuery("", $div); equals($span.length, 1, "Verify a span created with a div context works, #1763"); }); @@ -348,7 +399,7 @@ test("get(-Number)",function() { }) test("add(String|Element|Array|undefined)", function() { - expect(12); + expect(16); isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); isSet( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" ); @@ -357,6 +408,16 @@ test("add(String|Element|Array|undefined)", function() { // use jQuery([]).add(form.elements) instead. //equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" ); + var tmp = jQuery("
"); + + var x = jQuery([]).add(jQuery("

xxx

").appendTo(tmp)).add(jQuery("

xxx

").appendTo(tmp)); + equals( x[0].id, "x1", "Check on-the-fly element1" ); + equals( x[1].id, "x2", "Check on-the-fly element2" ); + + var x = jQuery([]).add(jQuery("

xxx

").appendTo(tmp)[0]).add(jQuery("

xxx

").appendTo(tmp)[0]); + equals( x[0].id, "x1", "Check on-the-fly element1" ); + equals( x[1].id, "x2", "Check on-the-fly element2" ); + var x = jQuery([]).add(jQuery("

xxx

")).add(jQuery("

xxx

")); equals( x[0].id, "x1", "Check on-the-fly element1" ); equals( x[1].id, "x2", "Check on-the-fly element2" ); @@ -386,6 +447,12 @@ test("each(Function)", function() { ok( pass, "Execute a function, Relative" ); }); +test("index()", function() { + expect(1); + + equals( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" ) +}); + test("index(Object|String|undefined)", function() { expect(16); @@ -435,7 +502,7 @@ test("jQuery.merge()", function() { }); test("jQuery.extend(Object, Object)", function() { - expect(20); + expect(23); var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, @@ -460,6 +527,22 @@ test("jQuery.extend(Object, Object)", function() { isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); + var empty = {}; + var optionsWithLength = { foo: { length: -1 } }; + jQuery.extend(true, empty, optionsWithLength); + isObj( empty.foo, optionsWithLength.foo, "The length property must copy correctly" ); + + empty = {}; + var optionsWithDate = { foo: { date: new Date } }; + jQuery.extend(true, empty, optionsWithDate); + isObj( empty.foo, optionsWithDate.foo, "Dates copy correctly" ); + + var myKlass = function() {}; + empty = {}; + var optionsWithCustomObject = { foo: { date: new myKlass } }; + jQuery.extend(true, empty, optionsWithCustomObject); + isObj( empty.foo, optionsWithCustomObject.foo, "Custom objects copy correctly" ); + var nullUndef; nullUndef = jQuery.extend({}, options, { xnumber2: null }); ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied"); @@ -577,3 +660,13 @@ test("jQuery.makeArray", function(){ ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" ); }); + +test("jQuery.isEmptyObject", function(){ + expect(2); + + equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" ); + equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" ); + + // What about this ? + // equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" ); +});