1 module("core", { teardown: moduleTeardown });
3 test("Unit Testing Environment", function () {
5 ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" );
6 ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" );
9 test("Basic requirements", function() {
11 ok( Array.prototype.push, "Array.push()" );
12 ok( Function.prototype.apply, "Function.apply()" );
13 ok( document.getElementById, "getElementById" );
14 ok( document.getElementsByTagName, "getElementsByTagName" );
15 ok( RegExp, "RegExp" );
16 ok( jQuery, "jQuery" );
20 testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
22 ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
23 deepEqual( errors, [], "No errors" );
24 ok( $(), "jQuery executes" );
27 test("jQuery()", function() {
31 code = jQuery("<code/>"),
32 img = jQuery("<img/>"),
33 div = jQuery("<div/><hr/><code/><b/>"),
43 // The $(html, props) signature can stealth-call any $.fn method, check for a
44 // few here but beware of modular builds where these methods may be excluded.
45 if ( jQuery.fn.click ) {
47 attrObj["click"] = function() { ok( exec, "Click executed." ); };
49 if ( jQuery.fn.width ) {
51 attrObj["width"] = 10;
53 if ( jQuery.fn.offset ) {
55 attrObj["offset"] = { "top": 1, "left": 1 };
57 if ( jQuery.fn.css ) {
59 attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
61 if ( jQuery.fn.attr ) {
63 attrObj.attr = { "desired": "very" };
68 // Basic constructor's behavior
69 equal( jQuery().length, 0, "jQuery() === jQuery([])" );
70 equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
71 equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
72 equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
73 equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
75 equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
77 // can actually yield more than one, when iframes are included, the window is an array as well
78 equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
81 // disabled since this test was doing nothing. i tried to fix it but i'm not sure
82 // what the expected behavior should even be. FF returns "\n" for the text node
83 // make sure this is handled
84 var crlfContainer = jQuery('<p>\r\n</p>');
85 var x = crlfContainer.contents().get(0).nodeValue;
86 equal( x, what???, "Check for \\r and \\n in jQuery()" );
89 /* // Disabled until we add this functionality in
92 jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
96 ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
98 equal( code.length, 1, "Correct number of elements generated for code" );
99 equal( code.parent().length, 0, "Make sure that the generated HTML has no parent." );
101 equal( img.length, 1, "Correct number of elements generated for img" );
102 equal( img.parent().length, 0, "Make sure that the generated HTML has no parent." );
104 equal( div.length, 4, "Correct number of elements generated for div hr code b" );
105 equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
107 equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
109 equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
111 elem = jQuery("<div/>", attrObj );
113 if ( jQuery.fn.width ) {
114 equal( elem[0].style.width, "10px", "jQuery() quick setter width");
117 if ( jQuery.fn.offset ) {
118 equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
121 if ( jQuery.fn.css ) {
122 equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
123 equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
126 if ( jQuery.fn.attr ) {
127 equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
130 equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
131 equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
132 equal( elem[0].className, "test2", "jQuery() quick setter class");
133 equal( elem[0].id, "test3", "jQuery() quick setter id");
136 elem.trigger("click");
138 // manually clean up detached elements
141 for ( i = 0; i < 3; ++i ) {
142 elem = jQuery("<input type='text' value='TEST' />");
144 equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
146 // manually clean up detached elements
149 for ( i = 0; i < 128; i++ ) {
154 test("jQuery(selector, context)", function() {
156 deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
157 deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
158 deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
161 test( "selector state", function() {
166 test = jQuery( undefined );
167 equal( test.selector, "", "Empty jQuery Selector" );
168 equal( test.context, undefined, "Empty jQuery Context" );
170 test = jQuery( document );
171 equal( test.selector, "", "Document Selector" );
172 equal( test.context, document, "Document Context" );
174 test = jQuery( document.body );
175 equal( test.selector, "", "Body Selector" );
176 equal( test.context, document.body, "Body Context" );
178 test = jQuery("#qunit-fixture");
179 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
180 equal( test.context, document, "#qunit-fixture Context" );
182 test = jQuery("#notfoundnono");
183 equal( test.selector, "#notfoundnono", "#notfoundnono Selector" );
184 equal( test.context, document, "#notfoundnono Context" );
186 test = jQuery( "#qunit-fixture", document );
187 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
188 equal( test.context, document, "#qunit-fixture Context" );
190 test = jQuery( "#qunit-fixture", document.body );
191 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
192 equal( test.context, document.body, "#qunit-fixture Context" );
195 test = jQuery( test );
196 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
197 equal( test.context, document.body, "#qunit-fixture Context" );
199 test = jQuery( document.body ).find("#qunit-fixture");
200 equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
201 equal( test.context, document.body, "#qunit-fixture find Context" );
204 test( "globalEval", function() {
206 Globals.register("globalEvalTest");
208 jQuery.globalEval("globalEvalTest = 1;");
209 equal( window.globalEvalTest, 1, "Test variable assignments are global" );
211 jQuery.globalEval("var globalEvalTest = 2;");
212 equal( window.globalEvalTest, 2, "Test variable declarations are global" );
214 jQuery.globalEval("this.globalEvalTest = 3;");
215 equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
218 test("noConflict", function() {
223 strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
224 strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
225 strictEqual( window["$"], original$, "Make sure $ was reverted." );
229 strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
230 strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
231 strictEqual( window["$"], original$, "Make sure $ was reverted." );
232 ok( $$().pushStack([]), "Make sure that jQuery still works." );
234 window["jQuery"] = jQuery = $$;
237 test("trim", function() {
240 var nbsp = String.fromCharCode(160);
242 equal( jQuery.trim("hello "), "hello", "trailing space" );
243 equal( jQuery.trim(" hello"), "hello", "leading space" );
244 equal( jQuery.trim(" hello "), "hello", "space on both sides" );
245 equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " );
247 equal( jQuery.trim(), "", "Nothing in." );
248 equal( jQuery.trim( undefined ), "", "Undefined" );
249 equal( jQuery.trim( null ), "", "Null" );
250 equal( jQuery.trim( 5 ), "5", "Number" );
251 equal( jQuery.trim( false ), "false", "Boolean" );
253 equal( jQuery.trim(" "), "", "space should be trimmed" );
254 equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" );
255 equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" );
256 equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" );
259 test("type", function() {
262 equal( jQuery.type(null), "null", "null" );
263 equal( jQuery.type(undefined), "undefined", "undefined" );
264 equal( jQuery.type(true), "boolean", "Boolean" );
265 equal( jQuery.type(false), "boolean", "Boolean" );
266 equal( jQuery.type(Boolean(true)), "boolean", "Boolean" );
267 equal( jQuery.type(0), "number", "Number" );
268 equal( jQuery.type(1), "number", "Number" );
269 equal( jQuery.type(Number(1)), "number", "Number" );
270 equal( jQuery.type(""), "string", "String" );
271 equal( jQuery.type("a"), "string", "String" );
272 equal( jQuery.type(String("a")), "string", "String" );
273 equal( jQuery.type({}), "object", "Object" );
274 equal( jQuery.type(/foo/), "regexp", "RegExp" );
275 equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" );
276 equal( jQuery.type([1]), "array", "Array" );
277 equal( jQuery.type(new Date()), "date", "Date" );
278 equal( jQuery.type(new Function("return;")), "function", "Function" );
279 equal( jQuery.type(function(){}), "function", "Function" );
280 equal( jQuery.type(new Error()), "error", "Error" );
281 equal( jQuery.type(window), "object", "Window" );
282 equal( jQuery.type(document), "object", "Document" );
283 equal( jQuery.type(document.body), "object", "Element" );
284 equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
285 equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
287 // Avoid Lint complaints
288 var MyString = String;
289 var MyNumber = Number;
290 var MyBoolean = Boolean;
291 var MyObject = Object;
292 equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" );
293 equal( jQuery.type(new MyNumber(1)), "number", "Number" );
294 equal( jQuery.type(new MyString("a")), "string", "String" );
295 equal( jQuery.type(new MyObject()), "object", "Object" );
298 asyncTest("isPlainObject", function() {
301 var pass, iframe, doc,
304 // The use case that we want to match
305 ok( jQuery.isPlainObject({}), "{}" );
307 // Not objects shouldn't be matched
308 ok( !jQuery.isPlainObject(""), "string" );
309 ok( !jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number" );
310 ok( !jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean" );
311 ok( !jQuery.isPlainObject(null), "null" );
312 ok( !jQuery.isPlainObject(undefined), "undefined" );
314 // Arrays shouldn't be matched
315 ok( !jQuery.isPlainObject([]), "array" );
317 // Instantiated objects shouldn't be matched
318 ok( !jQuery.isPlainObject(new Date()), "new Date" );
320 // Functions shouldn't be matched
321 ok( !jQuery.isPlainObject(fn), "fn" );
323 // Again, instantiated objects shouldn't be matched
324 ok( !jQuery.isPlainObject(new fn()), "new fn (no methods)" );
326 // Makes the function a little more realistic
327 // (and harder to detect, incidentally)
328 fn.prototype["someMethod"] = function(){};
330 // Again, instantiated objects shouldn't be matched
331 ok( !jQuery.isPlainObject(new fn()), "new fn" );
334 ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" );
337 ok( !jQuery.isPlainObject( window ), "window" );
341 jQuery.isPlainObject( window.location );
344 ok( pass, "Does not throw exceptions on host objects" );
346 // Objects from other windows should be matched
347 window.iframeCallback = function( otherObject, detail ) {
348 window.iframeCallback = undefined;
349 iframe.parentNode.removeChild( iframe );
350 ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
355 iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
356 doc = iframe.contentDocument || iframe.contentWindow.document;
358 doc.write("<body onload='window.parent.iframeCallback(Object);'>");
361 window.iframeDone( Object, "iframes not supported" );
365 test("isFunction", function() {
368 // Make sure that false values return false
369 ok( !jQuery.isFunction(), "No Value" );
370 ok( !jQuery.isFunction( null ), "null Value" );
371 ok( !jQuery.isFunction( undefined ), "undefined Value" );
372 ok( !jQuery.isFunction( "" ), "Empty String Value" );
373 ok( !jQuery.isFunction( 0 ), "0 Value" );
376 // Safari uses "(Internal Function)"
377 ok( jQuery.isFunction(String), "String Function("+String+")" );
378 ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
379 ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
380 ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
382 // When stringified, this could be misinterpreted
383 var mystr = "function";
384 ok( !jQuery.isFunction(mystr), "Function String" );
386 // When stringified, this could be misinterpreted
387 var myarr = [ "function" ];
388 ok( !jQuery.isFunction(myarr), "Function Array" );
390 // When stringified, this could be misinterpreted
391 var myfunction = { "function": "test" };
392 ok( !jQuery.isFunction(myfunction), "Function Object" );
394 // Make sure normal functions still work
395 var fn = function(){};
396 ok( jQuery.isFunction(fn), "Normal Function" );
398 var obj = document.createElement("object");
400 // Firefox says this is a function
401 ok( !jQuery.isFunction(obj), "Object Element" );
403 // IE says this is an object
404 // Since 1.3, this isn't supported (#2968)
405 //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
407 var nodes = document.body.childNodes;
409 // Safari says this is a function
410 ok( !jQuery.isFunction(nodes), "childNodes Property" );
412 var first = document.body.firstChild;
414 // Normal elements are reported ok everywhere
415 ok( !jQuery.isFunction(first), "A normal DOM Element" );
417 var input = document.createElement("input");
419 document.body.appendChild( input );
421 // IE says this is an object
422 // Since 1.3, this isn't supported (#2968)
423 //ok( jQuery.isFunction(input.focus), "A default function property" );
425 document.body.removeChild( input );
427 var a = document.createElement("a");
428 a.href = "some-function";
429 document.body.appendChild( a );
431 // This serializes with the word 'function' in it
432 ok( !jQuery.isFunction(a), "Anchor Element" );
434 document.body.removeChild( a );
436 // Recursive function calls have lengths and array-like properties
437 function callme(callback){
438 function fn(response){
442 ok( jQuery.isFunction(fn), "Recursive Function Call" );
444 fn({ some: "data" });
448 callme(function(){});
452 test( "isNumeric", function() {
455 var t = jQuery.isNumeric,
456 Traditionalists = /** @constructor */ function(n) {
458 this.toString = function(){
459 return String(this.value);
462 answer = new Traditionalists( "42" ),
463 rong = new Traditionalists( "Devo" );
465 ok( t("-10"), "Negative integer string");
466 ok( t("0"), "Zero string");
467 ok( t("5"), "Positive integer string");
468 ok( t(-16), "Negative integer number");
469 ok( t(0), "Zero integer number");
470 ok( t(32), "Positive integer number");
471 ok( t("040"), "Octal integer literal string");
472 // OctalIntegerLiteral has been deprecated since ES3/1999
473 // It doesn't pass lint, so disabling until a solution can be found
474 //ok( t(0144), "Octal integer literal");
475 ok( t("0xFF"), "Hexadecimal integer literal string");
476 ok( t(0xFFF), "Hexadecimal integer literal");
477 ok( t("-1.6"), "Negative floating point string");
478 ok( t("4.536"), "Positive floating point string");
479 ok( t(-2.6), "Negative floating point number");
480 ok( t(3.1415), "Positive floating point number");
481 ok( t(8e5), "Exponential notation");
482 ok( t("123e-2"), "Exponential notation string");
483 ok( t(answer), "Custom .toString returning number");
484 equal( t(""), false, "Empty string");
485 equal( t(" "), false, "Whitespace characters string");
486 equal( t("\t\t"), false, "Tab characters string");
487 equal( t("abcdefghijklm1234567890"), false, "Alphanumeric character string");
488 equal( t("xabcdefx"), false, "Non-numeric character string");
489 equal( t(true), false, "Boolean true literal");
490 equal( t(false), false, "Boolean false literal");
491 equal( t("bcfed5.2"), false, "Number with preceding non-numeric characters");
492 equal( t("7.2acdgs"), false, "Number with trailling non-numeric characters");
493 equal( t(undefined), false, "Undefined value");
494 equal( t(null), false, "Null value");
495 equal( t(NaN), false, "NaN value");
496 equal( t(Infinity), false, "Infinity primitive");
497 equal( t(Number.POSITIVE_INFINITY), false, "Positive Infinity");
498 equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity");
499 equal( t(rong), false, "Custom .toString returning non-number");
500 equal( t({}), false, "Empty object");
501 equal( t(function(){} ), false, "Instance of a function");
502 equal( t( new Date() ), false, "Instance of a Date");
503 equal( t(function(){} ), false, "Instance of a function");
506 test("isXMLDoc - HTML", function() {
509 ok( !jQuery.isXMLDoc( document ), "HTML document" );
510 ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" );
511 ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" );
513 var iframe = document.createElement("iframe");
514 document.body.appendChild( iframe );
517 var body = jQuery(iframe).contents()[0];
520 ok( !jQuery.isXMLDoc( body ), "Iframe body element" );
522 ok( false, "Iframe body element exception" );
526 ok( true, "Iframe body element - iframe not working correctly" );
529 document.body.removeChild( iframe );
532 test("XSS via location.hash", function() {
536 jQuery["_check9521"] = function(x){
537 ok( x, "script called from #id-like selector with inline handler" );
538 jQuery("#check9521").remove();
539 delete jQuery["_check9521"];
543 // This throws an error because it's processed like an id
544 jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo("#qunit-fixture");
546 jQuery["_check9521"](true);
550 test("isXMLDoc - XML", function() {
552 var xml = createDashboardXML();
553 ok( jQuery.isXMLDoc( xml ), "XML document" );
554 ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
555 ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
558 test("isWindow", function() {
561 ok( jQuery.isWindow(window), "window" );
562 ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
563 ok( !jQuery.isWindow(), "empty" );
564 ok( !jQuery.isWindow(null), "null" );
565 ok( !jQuery.isWindow(undefined), "undefined" );
566 ok( !jQuery.isWindow(document), "document" );
567 ok( !jQuery.isWindow(document.documentElement), "documentElement" );
568 ok( !jQuery.isWindow(""), "string" );
569 ok( !jQuery.isWindow(1), "number" );
570 ok( !jQuery.isWindow(true), "boolean" );
571 ok( !jQuery.isWindow({}), "object" );
572 ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
573 ok( !jQuery.isWindow(/window/), "regexp" );
574 ok( !jQuery.isWindow(function(){}), "function" );
577 test("jQuery('html')", function() {
581 jQuery["foo"] = false;
582 var s = jQuery("<script>jQuery.foo='test';</script>")[0];
583 ok( s, "Creating a script" );
584 ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" );
585 jQuery("body").append("<script>jQuery.foo='test';</script>");
586 ok( jQuery["foo"], "Executing a scripts contents in the right context" );
588 // Test multi-line HTML
589 var div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0];
590 equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." );
591 equal( div.firstChild.nodeType, 3, "Text node." );
592 equal( div.lastChild.nodeType, 3, "Text node." );
593 equal( div.childNodes[1].nodeType, 1, "Paragraph." );
594 equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." );
597 ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
599 ok( !jQuery("<script/>")[0].parentNode, "Create a script" );
601 ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." );
603 var j = jQuery("<span>hi</span> there <!-- mon ami -->");
604 ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
606 ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
608 ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
609 ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
611 // equal( jQuery("element[attribute='<div></div>']").length, 0, "When html is within brackets, do not recognize as html." );
612 // equal( jQuery("element[attribute=<div></div>]").length, 0, "When html is within brackets, do not recognize as html." );
613 // equal( jQuery("element:not(<div></div>)").length, 0, "When html is within parens, do not recognize as html." );
614 // equal( jQuery("\\<div\\>").length, 0, "Ignore escaped html characters" );
617 test("jQuery('massive html #7990')", function() {
621 var li = "<li>very very very very large html string</li>";
623 for ( i = 0; i < 30000; i += 1 ) {
624 html[html.length] = li;
626 html[html.length] = "</ul>";
627 html = jQuery(html.join(""))[0];
628 equal( html.nodeName.toLowerCase(), "ul");
629 equal( html.firstChild.nodeName.toLowerCase(), "li");
630 equal( html.childNodes.length, 30000 );
633 test("jQuery('html', context)", function() {
636 var $div = jQuery("<div/>")[0];
637 var $span = jQuery("<span/>", $div);
638 equal($span.length, 1, "Verify a span created with a div context works, #1763");
641 test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
644 var xml = createDashboardXML();
645 // tests for #1419 where IE was a problem
646 var tab = jQuery("tab", xml).eq(0);
647 equal( tab.text(), "blabla", "Verify initial text correct" );
649 equal( tab.text(), "newtext", "Verify new text correct" );
652 test("end()", function() {
654 equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "Check for end" );
655 ok( jQuery("#yahoo").end(), "Check for end with nothing to end" );
657 var x = jQuery("#yahoo");
659 equal( "Yahoo", jQuery("#yahoo").text(), "Check for non-destructive behaviour" );
662 test("length", function() {
664 equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
667 test("size()", function() {
669 equal( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" );
672 test("get()", function() {
674 deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
677 test("toArray()", function() {
679 deepEqual( jQuery("#qunit-fixture p").toArray(),
680 q("firstp","ap","sndp","en","sap","first"),
681 "Convert jQuery object to an Array" );
684 test("inArray()", function() {
688 p: q("firstp", "sap", "ap", "first"),
689 em: q("siblingnext", "siblingfirst"),
690 div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"),
691 a: q("mark", "groups", "google", "simon1"),
695 p: { elem: jQuery("#ap")[0], index: 2 },
696 em: { elem: jQuery("#siblingfirst")[0], index: 1 },
697 div: { elem: jQuery("#nothiddendiv")[0], index: 1 },
698 a: { elem: jQuery("#simon1")[0], index: 3 }
701 p: jQuery("#liveSpan1")[0],
702 em: jQuery("#nothiddendiv")[0],
706 jQuery.each( tests, function( key, obj ) {
707 equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" );
708 // Third argument (fromIndex)
709 equal( !!~jQuery.inArray( obj.elem, selections[ key ], 5 ), false, "elem is NOT in the array of selections given a starting index greater than its position" );
710 equal( !!~jQuery.inArray( obj.elem, selections[ key ], 1 ), true, "elem is in the array of selections given a starting index less than or equal to its position" );
711 equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" );
714 jQuery.each( falseTests, function( key, elem ) {
715 equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" );
720 test("get(Number)", function() {
722 equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
723 strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
726 test("get(-Number)",function() {
728 equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
729 strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
732 test("each(Function)", function() {
734 var div = jQuery("div");
735 div.each(function(){this.foo = "zoo";});
737 for ( var i = 0; i < div.size(); i++ ) {
738 if ( div.get(i).foo != "zoo" ) {
742 ok( pass, "Execute a function, Relative" );
745 test("slice()", function() {
748 var $links = jQuery("#ap a");
750 deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" );
751 deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" );
752 deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" );
753 deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" );
755 deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" );
756 deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" );
757 deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" );
760 test("first()/last()", function() {
763 var $links = jQuery("#ap a"), $none = jQuery("asdf");
765 deepEqual( $links.first().get(), q("google"), "first()" );
766 deepEqual( $links.last().get(), q("mark"), "last()" );
768 deepEqual( $none.first().get(), [], "first() none" );
769 deepEqual( $none.last().get(), [], "last() none" );
772 test("map()", function() {
776 jQuery("#ap").map(function() {
777 return jQuery( this ).find("a").get();
779 q( "google", "groups", "anchor1", "mark" ),
784 jQuery("#ap > a").map(function() {
785 return this.parentNode;
792 test("jQuery.map", function() {
795 var i, label, result, callback;
797 result = jQuery.map( [ 3, 4, 5 ], function( v, k ) {
800 equal( result.join(""), "012", "Map the keys from an array" );
802 result = jQuery.map( [ 3, 4, 5 ], function( v, k ) {
805 equal( result.join(""), "345", "Map the values from an array" );
807 result = jQuery.map( { a: 1, b: 2 }, function( v, k ) {
810 equal( result.join(""), "ab", "Map the keys from an object" );
812 result = jQuery.map( { a: 1, b: 2 }, function( v, k ) {
815 equal( result.join(""), "12", "Map the values from an object" );
817 result = jQuery.map( [ "a", undefined, null, "b" ], function( v, k ) {
820 equal( result.join(""), "ab", "Array iteration does not include undefined/null results" );
822 result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v, k ) {
825 equal( result.join(""), "ab", "Object iteration does not include undefined/null results" );
829 One: function( a ) {},
830 Two: function( a, b ) {}
832 callback = function( v, k ) {
833 equal( k, "foo", label + "-argument function treated like object" );
835 for ( i in result ) {
837 result[ i ].foo = "bar";
838 jQuery.map( result[ i ], callback );
842 "undefined": undefined,
847 "nonempty string": "string",
852 callback = function( v, k ) {
853 equal( k, "length", "Object with " + label + " length treated like object" );
855 for ( i in result ) {
857 jQuery.map( { length: result[ i ] }, callback );
861 "sparse Array": Array( 4 ),
862 "length: 1 plain object": { length: 1, "0": true },
863 "length: 2 plain object": { length: 2, "0": true, "1": true },
864 NodeList: document.getElementsByTagName("html")
866 callback = function( v, k ) {
867 if ( result[ label ] ) {
868 delete result[ label ];
869 equal( k, "0", label + " treated like array" );
872 for ( i in result ) {
874 jQuery.map( result[ i ], callback );
878 jQuery.map( { length: 0 }, function( v, k ) {
881 ok( !result, "length: 0 plain object treated like array" );
884 jQuery.map( document.getElementsByTagName("asdf"), function( v, k ) {
887 ok( !result, "empty NodeList treated like array" );
889 result = jQuery.map( Array(4), function( v, k ){
890 return k % 2 ? k : [k,k,k];
892 equal( result.join(""), "00012223", "Array results flattened (#2616)" );
895 test("jQuery.merge()", function() {
898 deepEqual( jQuery.merge([],[]), [], "Empty arrays" );
900 deepEqual( jQuery.merge([ 1 ],[ 2 ]), [ 1, 2 ], "Basic" );
901 deepEqual( jQuery.merge([ 1, 2 ], [ 3, 4 ]), [ 1, 2, 3, 4 ], "Basic" );
903 deepEqual( jQuery.merge([ 1, 2 ],[]), [ 1, 2 ], "Second empty" );
904 deepEqual( jQuery.merge([],[ 1, 2 ]), [ 1, 2 ], "First empty" );
906 // Fixed at [5998], #3641
907 deepEqual( jQuery.merge([ -2, -1 ], [ 0, 1, 2 ]), [ -2, -1 , 0, 1, 2 ],
908 "Second array including a zero (falsy)");
910 // After fixing #5527
911 deepEqual( jQuery.merge([], [ null, undefined ]), [ null, undefined ],
912 "Second array including null and undefined values");
913 deepEqual( jQuery.merge({ length: 0 }, [ 1, 2 ] ), { length: 2, 0: 1, 1: 2},
917 test("jQuery.extend(Object, Object)", function() {
920 var settings = { "xnumber1": 5, "xnumber2": 7, "xstring1": "peter", "xstring2": "pan" },
921 options = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
922 optionsCopy = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
923 merged = { "xnumber1": 5, "xnumber2": 1, "xstring1": "peter", "xstring2": "x", "xxx": "newstring" },
924 deep1 = { "foo": { "bar": true } },
925 deep1copy = { "foo": { "bar": true } },
926 deep2 = { "foo": { "baz": true }, "foo2": document },
927 deep2copy = { "foo": { "baz": true }, "foo2": document },
928 deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document },
930 nestedarray = { "arr": arr };
932 jQuery.extend(settings, options);
933 deepEqual( settings, merged, "Check if extended: settings must be extended" );
934 deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
936 jQuery.extend(settings, null, options);
937 deepEqual( settings, merged, "Check if extended: settings must be extended" );
938 deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
940 jQuery.extend(true, deep1, deep2);
941 deepEqual( deep1["foo"], deepmerged["foo"], "Check if foo: settings must be extended" );
942 deepEqual( deep2["foo"], deep2copy["foo"], "Check if not deep2: options must not be modified" );
943 equal( deep1["foo2"], document, "Make sure that a deep clone was not attempted on the document" );
945 ok( jQuery.extend(true, {}, nestedarray)["arr"] !== arr, "Deep extend of object must clone child array" );
948 ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array heve to be an Array" );
949 ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object heve to be an plain object" );
952 var optionsWithLength = { "foo": { "length": -1 } };
953 jQuery.extend(true, empty, optionsWithLength);
954 deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" );
957 var optionsWithDate = { "foo": { "date": new Date() } };
958 jQuery.extend(true, empty, optionsWithDate);
959 deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" );
962 var myKlass = function() {};
963 var customObject = new myKlass();
964 var optionsWithCustomObject = { "foo": { "date": customObject } };
966 jQuery.extend(true, empty, optionsWithCustomObject);
967 ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" );
969 // Makes the class a little more realistic
970 myKlass.prototype = { "someMethod": function(){} };
972 jQuery.extend(true, empty, optionsWithCustomObject);
973 ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" );
975 var MyNumber = Number;
976 var ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } );
977 ok( ret.foo == 5, "Wrapped numbers copy correctly" );
980 nullUndef = jQuery.extend({}, options, { "xnumber2": null });
981 ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied");
983 nullUndef = jQuery.extend({}, options, { "xnumber2": undefined });
984 ok( nullUndef["xnumber2"] === options["xnumber2"], "Check to make sure undefined values are not copied");
986 nullUndef = jQuery.extend({}, options, { "xnumber0": null });
987 ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted");
990 var recursive = { foo:target, bar:5 };
991 jQuery.extend(true, target, recursive);
992 deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
994 ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
995 equal( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
997 ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
998 ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
1000 ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
1001 ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
1003 var obj = { foo:null };
1004 jQuery.extend(true, obj, { foo:"notnull" } );
1005 equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
1008 jQuery.extend(func, { key: "value" } );
1009 equal( func.key, "value", "Verify a function can be extended" );
1011 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1012 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1013 options1 = { xnumber2: 1, xstring2: "x" },
1014 options1Copy = { xnumber2: 1, xstring2: "x" },
1015 options2 = { xstring2: "xx", xxx: "newstringx" },
1016 options2Copy = { xstring2: "xx", xxx: "newstringx" },
1017 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
1019 settings = jQuery.extend({}, defaults, options1, options2);
1020 deepEqual( settings, merged2, "Check if extended: settings must be extended" );
1021 deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
1022 deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
1023 deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
1026 test("jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed by object", function() {
1029 var result, initial = {
1030 // This will make "copyIsArray" true
1031 array: [ 1, 2, 3, 4 ],
1032 // If "copyIsArray" doesn't get reset to false, the check
1033 // will evaluate true and enter the array copy block
1034 // instead of the object copy block. Since the ternary in the
1035 // "copyIsArray" block will will evaluate to false
1036 // (check if operating on an array with ), this will be
1037 // replaced by an empty array.
1041 result = jQuery.extend( true, {}, initial );
1043 deepEqual( result, initial, "The [result] and [initial] have equal shape and values" );
1044 ok( !jQuery.isArray( result.object ), "result.object wasn't paved with an empty array" );
1047 test("jQuery.each(Object,Function)", function() {
1050 var i, label, seen, callback;
1053 jQuery.each( [ 3, 4, 5 ], function( k, v ) {
1056 deepEqual( seen, { "0": 3, "1": 4, "2": 5 }, "Array iteration" );
1059 jQuery.each( { name: "name", lang: "lang" }, function( k, v ) {
1062 deepEqual( seen, { name: "name", lang: "lang" }, "Object iteration" );
1065 jQuery.each( [ 1, 2, 3 ], function( k, v ) {
1071 deepEqual( seen, [ 1, 2 ] , "Broken array iteration" );
1074 jQuery.each( {"a": 1, "b": 2,"c": 3 }, function( k, v ) {
1078 deepEqual( seen, [ 1 ], "Broken object iteration" );
1081 Zero: function() {},
1082 One: function( a ) {},
1083 Two: function( a, b ) {}
1085 callback = function( k, v ) {
1086 equal( k, "foo", label + "-argument function treated like object" );
1090 seen[ i ].foo = "bar";
1091 jQuery.each( seen[ i ], callback );
1095 "undefined": undefined,
1100 "nonempty string": "string",
1101 "string \"0\"": "0",
1105 callback = function( k, v ) {
1106 equal( k, "length", "Object with " + label + " length treated like object" );
1110 jQuery.each( { length: seen[ i ] }, callback );
1114 "sparse Array": Array( 4 ),
1115 "length: 1 plain object": { length: 1, "0": true },
1116 "length: 2 plain object": { length: 2, "0": true, "1": true },
1117 NodeList: document.getElementsByTagName("html")
1119 callback = function( k, v ) {
1120 if ( seen[ label ] ) {
1121 delete seen[ label ];
1122 equal( k, "0", label + " treated like array" );
1128 jQuery.each( seen[ i ], callback );
1132 jQuery.each( { length: 0 }, function( k, v ) {
1135 ok( !seen, "length: 0 plain object treated like array" );
1138 jQuery.each( document.getElementsByTagName("asdf"), function( k, v ) {
1141 ok( !seen, "empty NodeList treated like array" );
1144 jQuery.each( document.styleSheets, function() {
1147 equal( i, 2, "Iteration over document.styleSheets" );
1150 test("jQuery.makeArray", function(){
1153 equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
1155 equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
1157 equal( (function(arg1, arg2){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
1159 equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
1161 equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
1163 equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
1165 equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
1167 equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
1169 equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
1171 equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
1173 ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
1175 // function, is tricky as it has length
1176 equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
1178 //window, also has length
1179 equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
1181 equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
1183 // Some nodes inherit traits of nodelists
1184 ok( jQuery.makeArray(document.getElementById("form")).length >= 13,
1185 "Pass makeArray a form (treat as elements)" );
1188 test("jQuery.inArray", function(){
1191 equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
1193 equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
1195 equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
1198 test("jQuery.isEmptyObject", function(){
1201 equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
1202 equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
1204 // What about this ?
1205 // equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
1208 test("jQuery.proxy", function(){
1211 var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); };
1212 var thisObject = { foo: "bar", method: test };
1214 // Make sure normal works
1215 test.call( thisObject );
1218 jQuery.proxy( test, thisObject )();
1220 // Another take on it
1221 jQuery.proxy( thisObject, "method" )();
1223 // Make sure it doesn't freak out
1224 equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
1226 // Partial application
1227 var test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
1228 jQuery.proxy( test2, null, "pre-applied" )();
1230 // Partial application w/ normal arguments
1231 var test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
1232 jQuery.proxy( test3, null, "pre-applied" )( "normal" );
1235 var test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
1236 jQuery.proxy( test4, "meth" )( "boom" );
1238 // jQuery 1.9 improved currying with `this` object
1239 var fn = function() {
1240 equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
1241 equal( this.foo, "bar", "this-object passed" );
1243 var cb = jQuery.proxy( fn, null, "arg1", "arg2" );
1244 cb.call( thisObject, "arg3" );
1247 test("jQuery.parseHTML", function() {
1252 equal( jQuery.parseHTML(), null, "Nothing in, null out." );
1253 equal( jQuery.parseHTML( null ), null, "Null in, null out." );
1254 equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
1256 jQuery.parseHTML( "<div></div>", document.getElementById("form") );
1257 }, "Passing an element as the context raises an exception (context should be a document)");
1259 nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML );
1260 ok( nodes.length > 4, "Parse a large html string" );
1261 equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
1263 html = "<script>undefined()</script>";
1264 equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
1265 equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
1267 html += "<div></div>";
1268 equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
1269 equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve script position");
1271 equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" );
1272 equal( jQuery.parseHTML( "\t<div></div>" )[0].nodeValue, "\t", "Preserve leading whitespace" );
1274 equal( jQuery.parseHTML(" <div/> ")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
1276 html = jQuery.parseHTML( "<div>test div</div>" );
1278 equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
1279 equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" );
1281 equal( jQuery.parseHTML("<span><span>").length, 1, "Incorrect html-strings should not break anything" );
1282 equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11,
1283 "parentNode should be documentFragment for wrapMap (variable in manipulation module) elements too" );
1286 test("jQuery.parseJSON", function(){
1289 equal( jQuery.parseJSON( null ), null, "Actual null returns null" );
1290 equal( jQuery.isEmptyObject( jQuery.parseJSON("{}") ), true, "Empty object returns empty object" );
1291 deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object parses" );
1292 deepEqual( jQuery.parseJSON("\n{\"test\":1}"), { "test": 1 }, "Leading whitespaces are ignored." );
1295 }, null, "Undefined raises an error" );
1296 raises( function() {
1297 jQuery.parseJSON( "" );
1298 }, null, "Empty string raises an error" );
1300 jQuery.parseJSON("''");
1301 }, null, "Single-quoted string raises an error" );
1303 jQuery.parseJSON("{a:1}");
1304 }, null, "Unquoted property raises an error" );
1306 jQuery.parseJSON("{'a':1}");
1307 }, null, "Single-quoted property raises an error" );
1310 test("jQuery.parseXML", 8, function(){
1313 xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" );
1314 tmp = xml.getElementsByTagName( "p" )[ 0 ];
1315 ok( !!tmp, "<p> present in document" );
1316 tmp = tmp.getElementsByTagName( "b" )[ 0 ];
1317 ok( !!tmp, "<b> present in document" );
1318 strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" );
1320 strictEqual( e, undefined, "unexpected error" );
1323 xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" );
1324 ok( false, "invalid xml not detected" );
1326 strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" );
1329 xml = jQuery.parseXML( "" );
1330 strictEqual( xml, null, "empty string => null document" );
1331 xml = jQuery.parseXML();
1332 strictEqual( xml, null, "undefined string => null document" );
1333 xml = jQuery.parseXML( null );
1334 strictEqual( xml, null, "null string => null document" );
1335 xml = jQuery.parseXML( true );
1336 strictEqual( xml, null, "non-string => null document" );
1338 ok( false, "empty input throws exception" );
1342 test("jQuery.camelCase()", function() {
1345 "foo-bar": "fooBar",
1346 "foo-bar-baz": "fooBarBaz",
1347 "girl-u-want": "girlUWant",
1348 "the-4th-dimension": "the4thDimension",
1349 "-o-tannenbaum": "OTannenbaum",
1350 "-moz-illa": "MozIlla",
1351 "-ms-take": "msTake"
1356 jQuery.each( tests, function( key, val ) {
1357 equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );