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 test("jQuery()", function() {
24 code = jQuery("<code/>"),
25 img = jQuery("<img/>"),
26 div = jQuery("<div/><hr/><code/><b/>"),
36 // The $(html, props) signature can stealth-call any $.fn method, check for a
37 // few here but beware of modular builds where these methods may be excluded.
38 if ( jQuery.fn.click ) {
40 attrObj["click"] = function() { ok( exec, "Click executed." ); };
42 if ( jQuery.fn.width ) {
44 attrObj["width"] = 10;
46 if ( jQuery.fn.offset ) {
48 attrObj["offset"] = { "top": 1, "left": 1 };
50 if ( jQuery.fn.css ) {
52 attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
54 if ( jQuery.fn.attr ) {
56 attrObj.attr = { "desired": "very" };
61 // Basic constructor's behavior
62 equal( jQuery().length, 0, "jQuery() === jQuery([])" );
63 equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
64 equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
65 equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
66 equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
68 equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
70 // can actually yield more than one, when iframes are included, the window is an array as well
71 equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
74 // disabled since this test was doing nothing. i tried to fix it but i'm not sure
75 // what the expected behavior should even be. FF returns "\n" for the text node
76 // make sure this is handled
77 var crlfContainer = jQuery('<p>\r\n</p>');
78 var x = crlfContainer.contents().get(0).nodeValue;
79 equal( x, what???, "Check for \\r and \\n in jQuery()" );
82 /* // Disabled until we add this functionality in
85 jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
89 ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
91 equal( code.length, 1, "Correct number of elements generated for code" );
92 equal( code.parent().length, 0, "Make sure that the generated HTML has no parent." );
94 equal( img.length, 1, "Correct number of elements generated for img" );
95 equal( img.parent().length, 0, "Make sure that the generated HTML has no parent." );
97 equal( div.length, 4, "Correct number of elements generated for div hr code b" );
98 equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
100 equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
102 equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
104 elem = jQuery(" <em>hello</em>")[0];
105 equal( elem.nodeName.toLowerCase(), "em", "leading space" );
107 elem = jQuery("\n\n<em>world</em>")[0];
108 equal( elem.nodeName.toLowerCase(), "em", "leading newlines" );
110 elem = jQuery("<div/>", attrObj );
112 if ( jQuery.fn.width ) {
113 equal( elem[0].style.width, "10px", "jQuery() quick setter width");
116 if ( jQuery.fn.offset ) {
117 equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
120 if ( jQuery.fn.css ) {
121 equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
122 equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
125 if ( jQuery.fn.attr ) {
126 equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
129 equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
130 equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
131 equal( elem[0].className, "test2", "jQuery() quick setter class");
132 equal( elem[0].id, "test3", "jQuery() quick setter id");
135 elem.trigger("click");
137 // manually clean up detached elements
140 for ( i = 0; i < 3; ++i ) {
141 elem = jQuery("<input type='text' value='TEST' />");
143 equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
145 // manually clean up detached elements
148 for ( i = 0; i < 128; i++ ) {
153 test("jQuery(selector, context)", function() {
155 deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
156 deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
157 deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
160 test( "selector state", function() {
165 test = jQuery( undefined );
166 equal( test.selector, "", "Empty jQuery Selector" );
167 equal( test.context, undefined, "Empty jQuery Context" );
169 test = jQuery( document );
170 equal( test.selector, "", "Document Selector" );
171 equal( test.context, document, "Document Context" );
173 test = jQuery( document.body );
174 equal( test.selector, "", "Body Selector" );
175 equal( test.context, document.body, "Body Context" );
177 test = jQuery("#qunit-fixture");
178 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
179 equal( test.context, document, "#qunit-fixture Context" );
181 test = jQuery("#notfoundnono");
182 equal( test.selector, "#notfoundnono", "#notfoundnono Selector" );
183 equal( test.context, document, "#notfoundnono Context" );
185 test = jQuery( "#qunit-fixture", document );
186 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
187 equal( test.context, document, "#qunit-fixture Context" );
189 test = jQuery( "#qunit-fixture", document.body );
190 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
191 equal( test.context, document.body, "#qunit-fixture Context" );
194 test = jQuery( test );
195 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
196 equal( test.context, document.body, "#qunit-fixture Context" );
198 test = jQuery( document.body ).find("#qunit-fixture");
199 equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
200 equal( test.context, document.body, "#qunit-fixture find Context" );
203 test( "globalEval", function() {
205 Globals.register("globalEvalTest");
207 jQuery.globalEval("globalEvalTest = 1;");
208 equal( window.globalEvalTest, 1, "Test variable assignments are global" );
210 jQuery.globalEval("var globalEvalTest = 2;");
211 equal( window.globalEvalTest, 2, "Test variable declarations are global" );
213 jQuery.globalEval("this.globalEvalTest = 3;");
214 equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
217 test( "globalEval with 'use strict'", function() {
219 Globals.register("strictEvalTest");
221 jQuery.globalEval("'use strict'; var strictEvalTest = 1;");
222 equal( window.strictEvalTest, 1, "Test variable declarations are global (strict mode)" );
225 test("noConflict", function() {
230 strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
231 strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
232 strictEqual( window["$"], original$, "Make sure $ was reverted." );
236 strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
237 strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
238 strictEqual( window["$"], original$, "Make sure $ was reverted." );
239 ok( $$().pushStack([]), "Make sure that jQuery still works." );
241 window["jQuery"] = jQuery = $$;
244 test("trim", function() {
247 var nbsp = String.fromCharCode(160);
249 equal( jQuery.trim("hello "), "hello", "trailing space" );
250 equal( jQuery.trim(" hello"), "hello", "leading space" );
251 equal( jQuery.trim(" hello "), "hello", "space on both sides" );
252 equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " );
254 equal( jQuery.trim(), "", "Nothing in." );
255 equal( jQuery.trim( undefined ), "", "Undefined" );
256 equal( jQuery.trim( null ), "", "Null" );
257 equal( jQuery.trim( 5 ), "5", "Number" );
258 equal( jQuery.trim( false ), "false", "Boolean" );
260 equal( jQuery.trim(" "), "", "space should be trimmed" );
261 equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" );
262 equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" );
263 equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" );
266 test("type", function() {
269 equal( jQuery.type(null), "null", "null" );
270 equal( jQuery.type(undefined), "undefined", "undefined" );
271 equal( jQuery.type(true), "boolean", "Boolean" );
272 equal( jQuery.type(false), "boolean", "Boolean" );
273 equal( jQuery.type(Boolean(true)), "boolean", "Boolean" );
274 equal( jQuery.type(0), "number", "Number" );
275 equal( jQuery.type(1), "number", "Number" );
276 equal( jQuery.type(Number(1)), "number", "Number" );
277 equal( jQuery.type(""), "string", "String" );
278 equal( jQuery.type("a"), "string", "String" );
279 equal( jQuery.type(String("a")), "string", "String" );
280 equal( jQuery.type({}), "object", "Object" );
281 equal( jQuery.type(/foo/), "regexp", "RegExp" );
282 equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" );
283 equal( jQuery.type([1]), "array", "Array" );
284 equal( jQuery.type(new Date()), "date", "Date" );
285 equal( jQuery.type(new Function("return;")), "function", "Function" );
286 equal( jQuery.type(function(){}), "function", "Function" );
287 equal( jQuery.type(new Error()), "error", "Error" );
288 equal( jQuery.type(window), "object", "Window" );
289 equal( jQuery.type(document), "object", "Document" );
290 equal( jQuery.type(document.body), "object", "Element" );
291 equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
292 equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
294 // Avoid Lint complaints
295 var MyString = String,
299 equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" );
300 equal( jQuery.type(new MyNumber(1)), "number", "Number" );
301 equal( jQuery.type(new MyString("a")), "string", "String" );
302 equal( jQuery.type(new MyObject()), "object", "Object" );
305 asyncTest("isPlainObject", function() {
308 var pass, iframe, doc,
311 // The use case that we want to match
312 ok( jQuery.isPlainObject({}), "{}" );
314 // Not objects shouldn't be matched
315 ok( !jQuery.isPlainObject(""), "string" );
316 ok( !jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number" );
317 ok( !jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean" );
318 ok( !jQuery.isPlainObject(null), "null" );
319 ok( !jQuery.isPlainObject(undefined), "undefined" );
321 // Arrays shouldn't be matched
322 ok( !jQuery.isPlainObject([]), "array" );
324 // Instantiated objects shouldn't be matched
325 ok( !jQuery.isPlainObject(new Date()), "new Date" );
327 // Functions shouldn't be matched
328 ok( !jQuery.isPlainObject(fn), "fn" );
330 // Again, instantiated objects shouldn't be matched
331 ok( !jQuery.isPlainObject(new fn()), "new fn (no methods)" );
333 // Makes the function a little more realistic
334 // (and harder to detect, incidentally)
335 fn.prototype["someMethod"] = function(){};
337 // Again, instantiated objects shouldn't be matched
338 ok( !jQuery.isPlainObject(new fn()), "new fn" );
341 ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" );
344 ok( !jQuery.isPlainObject( window ), "window" );
348 jQuery.isPlainObject( window.location );
351 ok( pass, "Does not throw exceptions on host objects" );
353 // Objects from other windows should be matched
354 Globals.register("iframeDone");
355 window.iframeDone = function( otherObject, detail ) {
356 window.iframeDone = undefined;
357 iframe.parentNode.removeChild( iframe );
358 ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
363 iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
364 doc = iframe.contentDocument || iframe.contentWindow.document;
366 doc.write("<body onload='window.parent.iframeDone(Object);'>");
369 window.iframeDone( Object, "iframes not supported" );
373 test("isFunction", function() {
376 var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
378 // Make sure that false values return false
379 ok( !jQuery.isFunction(), "No Value" );
380 ok( !jQuery.isFunction( null ), "null Value" );
381 ok( !jQuery.isFunction( undefined ), "undefined Value" );
382 ok( !jQuery.isFunction( "" ), "Empty String Value" );
383 ok( !jQuery.isFunction( 0 ), "0 Value" );
386 ok( jQuery.isFunction(String), "String Function("+String+")" );
387 ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
388 ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
389 ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
391 // When stringified, this could be misinterpreted
393 ok( !jQuery.isFunction(mystr), "Function String" );
395 // When stringified, this could be misinterpreted
396 myarr = [ "function" ];
397 ok( !jQuery.isFunction(myarr), "Function Array" );
399 // When stringified, this could be misinterpreted
400 myfunction = { "function": "test" };
401 ok( !jQuery.isFunction(myfunction), "Function Object" );
403 // Make sure normal functions still work
405 ok( jQuery.isFunction(fn), "Normal Function" );
407 obj = document.createElement("object");
409 // Firefox says this is a function
410 ok( !jQuery.isFunction(obj), "Object Element" );
412 // Since 1.3, this isn't supported (#2968)
413 //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
415 nodes = document.body.childNodes;
417 // Safari says this is a function
418 ok( !jQuery.isFunction(nodes), "childNodes Property" );
420 first = document.body.firstChild;
422 // Normal elements are reported ok everywhere
423 ok( !jQuery.isFunction(first), "A normal DOM Element" );
425 input = document.createElement("input");
427 document.body.appendChild( input );
429 // Since 1.3, this isn't supported (#2968)
430 //ok( jQuery.isFunction(input.focus), "A default function property" );
432 document.body.removeChild( input );
434 a = document.createElement("a");
435 a.href = "some-function";
436 document.body.appendChild( a );
438 // This serializes with the word 'function' in it
439 ok( !jQuery.isFunction(a), "Anchor Element" );
441 document.body.removeChild( a );
443 // Recursive function calls have lengths and array-like properties
444 function callme(callback){
445 function fn(response){
449 ok( jQuery.isFunction(fn), "Recursive Function Call" );
451 fn({ some: "data" });
455 callme(function(){});
459 test( "isNumeric", function() {
462 var t = jQuery.isNumeric,
463 Traditionalists = /** @constructor */ function(n) {
465 this.toString = function(){
466 return String(this.value);
469 answer = new Traditionalists( "42" ),
470 rong = new Traditionalists( "Devo" );
472 ok( t("-10"), "Negative integer string");
473 ok( t("0"), "Zero string");
474 ok( t("5"), "Positive integer string");
475 ok( t(-16), "Negative integer number");
476 ok( t(0), "Zero integer number");
477 ok( t(32), "Positive integer number");
478 ok( t("040"), "Octal integer literal string");
479 // OctalIntegerLiteral has been deprecated since ES3/1999
480 // It doesn't pass lint, so disabling until a solution can be found
481 //ok( t(0144), "Octal integer literal");
482 ok( t("0xFF"), "Hexadecimal integer literal string");
483 ok( t(0xFFF), "Hexadecimal integer literal");
484 ok( t("-1.6"), "Negative floating point string");
485 ok( t("4.536"), "Positive floating point string");
486 ok( t(-2.6), "Negative floating point number");
487 ok( t(3.1415), "Positive floating point number");
488 ok( t(8e5), "Exponential notation");
489 ok( t("123e-2"), "Exponential notation string");
490 ok( t(answer), "Custom .toString returning number");
491 equal( t(""), false, "Empty string");
492 equal( t(" "), false, "Whitespace characters string");
493 equal( t("\t\t"), false, "Tab characters string");
494 equal( t("abcdefghijklm1234567890"), false, "Alphanumeric character string");
495 equal( t("xabcdefx"), false, "Non-numeric character string");
496 equal( t(true), false, "Boolean true literal");
497 equal( t(false), false, "Boolean false literal");
498 equal( t("bcfed5.2"), false, "Number with preceding non-numeric characters");
499 equal( t("7.2acdgs"), false, "Number with trailling non-numeric characters");
500 equal( t(undefined), false, "Undefined value");
501 equal( t(null), false, "Null value");
502 equal( t(NaN), false, "NaN value");
503 equal( t(Infinity), false, "Infinity primitive");
504 equal( t(Number.POSITIVE_INFINITY), false, "Positive Infinity");
505 equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity");
506 equal( t(rong), false, "Custom .toString returning non-number");
507 equal( t({}), false, "Empty object");
508 equal( t( [] ), false, "Empty array" );
509 equal( t( [ 42 ] ), false, "Array with one number" );
510 equal( t(function(){} ), false, "Instance of a function");
511 equal( t( new Date() ), false, "Instance of a Date");
512 equal( t(function(){} ), false, "Instance of a function");
515 test("isXMLDoc - HTML", function() {
518 ok( !jQuery.isXMLDoc( document ), "HTML document" );
519 ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" );
520 ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" );
523 iframe = document.createElement("iframe");
524 document.body.appendChild( iframe );
527 body = jQuery(iframe).contents()[0];
530 ok( !jQuery.isXMLDoc( body ), "Iframe body element" );
532 ok( false, "Iframe body element exception" );
536 ok( true, "Iframe body element - iframe not working correctly" );
539 document.body.removeChild( iframe );
542 test("XSS via location.hash", function() {
546 jQuery["_check9521"] = function(x){
547 ok( x, "script called from #id-like selector with inline handler" );
548 jQuery("#check9521").remove();
549 delete jQuery["_check9521"];
553 // This throws an error because it's processed like an id
554 jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo("#qunit-fixture");
556 jQuery["_check9521"](true);
560 test("isXMLDoc - XML", function() {
562 var xml = createDashboardXML();
563 ok( jQuery.isXMLDoc( xml ), "XML document" );
564 ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
565 ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
568 test("isWindow", function() {
571 ok( jQuery.isWindow(window), "window" );
572 ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
573 ok( !jQuery.isWindow(), "empty" );
574 ok( !jQuery.isWindow(null), "null" );
575 ok( !jQuery.isWindow(undefined), "undefined" );
576 ok( !jQuery.isWindow(document), "document" );
577 ok( !jQuery.isWindow(document.documentElement), "documentElement" );
578 ok( !jQuery.isWindow(""), "string" );
579 ok( !jQuery.isWindow(1), "number" );
580 ok( !jQuery.isWindow(true), "boolean" );
581 ok( !jQuery.isWindow({}), "object" );
582 ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
583 ok( !jQuery.isWindow(/window/), "regexp" );
584 ok( !jQuery.isWindow(function(){}), "function" );
587 test("jQuery('html')", function() {
592 jQuery["foo"] = false;
593 s = jQuery("<script>jQuery.foo='test';</script>")[0];
594 ok( s, "Creating a script" );
595 ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" );
596 jQuery("body").append("<script>jQuery.foo='test';</script>");
597 ok( jQuery["foo"], "Executing a scripts contents in the right context" );
599 // Test multi-line HTML
600 div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0];
601 equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." );
602 equal( div.firstChild.nodeType, 3, "Text node." );
603 equal( div.lastChild.nodeType, 3, "Text node." );
604 equal( div.childNodes[1].nodeType, 1, "Paragraph." );
605 equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." );
607 ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
609 ok( !jQuery("<script/>")[0].parentNode, "Create a script" );
611 ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." );
613 j = jQuery("<span>hi</span> there <!-- mon ami -->");
614 ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
616 ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
618 ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
619 ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
621 equal( jQuery( "element[attribute='<div></div>']" ).length, 0,
622 "When html is within brackets, do not recognize as html." );
623 //equal( jQuery( "element[attribute=<div></div>]" ).length, 0,
624 // "When html is within brackets, do not recognize as html." );
625 equal( jQuery( "element:not(<div></div>)" ).length, 0,
626 "When html is within parens, do not recognize as html." );
627 equal( jQuery( "\\<div\\>" ).length, 0, "Ignore escaped html characters" );
630 test("jQuery('massive html #7990')", function() {
634 li = "<li>very very very very large html string</li>",
637 for ( i = 0; i < 30000; i += 1 ) {
638 html[html.length] = li;
640 html[html.length] = "</ul>";
641 html = jQuery(html.join(""))[0];
642 equal( html.nodeName.toLowerCase(), "ul");
643 equal( html.firstChild.nodeName.toLowerCase(), "li");
644 equal( html.childNodes.length, 30000 );
647 test("jQuery('html', context)", function() {
650 var $div = jQuery("<div/>")[0],
651 $span = jQuery("<span/>", $div);
652 equal($span.length, 1, "verify a span created with a div context works, #1763");
655 test("jQuery(selector, xml).text(str) - loaded via xml document", function() {
658 var xml = createDashboardXML(),
659 // tests for #1419 where ie was a problem
660 tab = jQuery("tab", xml).eq(0);
661 equal( tab.text(), "blabla", "verify initial text correct" );
663 equal( tab.text(), "newtext", "verify new text correct" );
666 test("end()", function() {
668 equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "check for end" );
669 ok( jQuery("#yahoo").end(), "check for end with nothing to end" );
671 var x = jQuery("#yahoo");
673 equal( "Yahoo", jQuery("#yahoo").text(), "check for non-destructive behaviour" );
676 test("length", function() {
678 equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
681 test("get()", function() {
683 deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
686 test("toArray()", function() {
688 deepEqual( jQuery("#qunit-fixture p").toArray(),
689 q("firstp","ap","sndp","en","sap","first"),
690 "Convert jQuery object to an Array" );
693 test("inArray()", function() {
697 p: q("firstp", "sap", "ap", "first"),
698 em: q("siblingnext", "siblingfirst"),
699 div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"),
700 a: q("mark", "groups", "google", "simon1"),
704 p: { elem: jQuery("#ap")[0], index: 2 },
705 em: { elem: jQuery("#siblingfirst")[0], index: 1 },
706 div: { elem: jQuery("#nothiddendiv")[0], index: 1 },
707 a: { elem: jQuery("#simon1")[0], index: 3 }
710 p: jQuery("#liveSpan1")[0],
711 em: jQuery("#nothiddendiv")[0],
715 jQuery.each( tests, function( key, obj ) {
716 equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" );
717 // Third argument (fromIndex)
718 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" );
719 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" );
720 equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" );
723 jQuery.each( falseTests, function( key, elem ) {
724 equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" );
729 test("get(Number)", function() {
731 equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
732 strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
735 test("get(-Number)",function() {
737 equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
738 strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
741 test("each(Function)", function() {
746 div.each(function(){this.foo = "zoo";});
748 for ( i = 0; i < div.length; i++ ) {
749 if ( div.get(i).foo !== "zoo" ) {
753 ok( pass, "Execute a function, Relative" );
756 test("slice()", function() {
759 var $links = jQuery("#ap a");
761 deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" );
762 deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" );
763 deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" );
764 deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" );
766 deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" );
767 deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" );
768 deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" );
771 test("first()/last()", function() {
774 var $links = jQuery("#ap a"), $none = jQuery("asdf");
776 deepEqual( $links.first().get(), q("google"), "first()" );
777 deepEqual( $links.last().get(), q("mark"), "last()" );
779 deepEqual( $none.first().get(), [], "first() none" );
780 deepEqual( $none.last().get(), [], "last() none" );
783 test("map()", function() {
787 jQuery("#ap").map(function() {
788 return jQuery( this ).find("a").get();
790 q( "google", "groups", "anchor1", "mark" ),
795 jQuery("#ap > a").map(function() {
796 return this.parentNode;
803 test("jQuery.map", function() {
806 var i, label, result, callback;
808 result = jQuery.map( [ 3, 4, 5 ], function( v, k ) {
811 equal( result.join(""), "012", "Map the keys from an array" );
813 result = jQuery.map( [ 3, 4, 5 ], function( v ) {
816 equal( result.join(""), "345", "Map the values from an array" );
818 result = jQuery.map( { a: 1, b: 2 }, function( v, k ) {
821 equal( result.join(""), "ab", "Map the keys from an object" );
823 result = jQuery.map( { a: 1, b: 2 }, function( v ) {
826 equal( result.join(""), "12", "Map the values from an object" );
828 result = jQuery.map( [ "a", undefined, null, "b" ], function( v ) {
831 equal( result.join(""), "ab", "Array iteration does not include undefined/null results" );
833 result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v ) {
836 equal( result.join(""), "ab", "Object iteration does not include undefined/null results" );
840 One: function( a ) { a = a; },
841 Two: function( a, b ) { a = a; b = b; }
843 callback = function( v, k ) {
844 equal( k, "foo", label + "-argument function treated like object" );
846 for ( i in result ) {
848 result[ i ].foo = "bar";
849 jQuery.map( result[ i ], callback );
853 "undefined": undefined,
858 "nonempty string": "string",
863 callback = function( v, k ) {
864 equal( k, "length", "Object with " + label + " length treated like object" );
866 for ( i in result ) {
868 jQuery.map( { length: result[ i ] }, callback );
872 "sparse Array": Array( 4 ),
873 "length: 1 plain object": { length: 1, "0": true },
874 "length: 2 plain object": { length: 2, "0": true, "1": true },
875 NodeList: document.getElementsByTagName("html")
877 callback = function( v, k ) {
878 if ( result[ label ] ) {
879 delete result[ label ];
880 equal( k, "0", label + " treated like array" );
883 for ( i in result ) {
885 jQuery.map( result[ i ], callback );
889 jQuery.map( { length: 0 }, function() {
892 ok( !result, "length: 0 plain object treated like array" );
895 jQuery.map( document.getElementsByTagName("asdf"), function() {
898 ok( !result, "empty NodeList treated like array" );
900 result = jQuery.map( Array(4), function( v, k ){
901 return k % 2 ? k : [k,k,k];
903 equal( result.join(""), "00012223", "Array results flattened (#2616)" );
906 test("jQuery.merge()", function() {
910 jQuery.merge( [], [] ),
916 jQuery.merge( [ 1 ], [ 2 ] ),
918 "Basic (single-element)"
921 jQuery.merge( [ 1, 2 ], [ 3, 4 ] ),
923 "Basic (multiple-element)"
927 jQuery.merge( [ 1, 2 ], [] ),
932 jQuery.merge( [], [ 1, 2 ] ),
937 // Fixed at [5998], #3641
939 jQuery.merge( [ -2, -1 ], [ 0, 1, 2 ] ),
940 [ -2, -1 , 0, 1, 2 ],
941 "Second array including a zero (falsy)"
944 // After fixing #5527
946 jQuery.merge( [], [ null, undefined ] ),
948 "Second array including null and undefined values"
951 jQuery.merge( { length: 0 }, [ 1, 2 ] ),
952 { length: 2, 0: 1, 1: 2 },
956 jQuery.merge( [ 1, 2 ], { length: 1, 0: 3 } ),
962 jQuery.merge( [], document.getElementById("lengthtest").getElementsByTagName("input") ),
963 [ document.getElementById("length"), document.getElementById("idTest") ],
968 test("jQuery.grep()", function() {
971 var searchCriterion = function( value ) {
972 return value % 2 === 0;
975 deepEqual( jQuery.grep( [], searchCriterion ), [], "Empty array" );
976 deepEqual( jQuery.grep( new Array(4), searchCriterion ), [], "Sparse array" );
978 deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ), [ 2, 4, 6 ], "Satisfying elements present" );
979 deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion ), [], "Satisfying elements absent" );
981 deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ), [ 1, 3, 5 ], "Satisfying elements present and grep inverted" );
982 deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion, true ), [1, 3, 5, 7], "Satisfying elements absent and grep inverted" );
984 deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ), [ 2, 4, 6 ], "Satisfying elements present but grep explicitly uninverted" );
985 deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ), [], "Satisfying elements absent and grep explicitly uninverted" );
988 test("jQuery.extend(Object, Object)", function() {
991 var empty, optionsWithLength, optionsWithDate, myKlass,
992 customObject, optionsWithCustomObject, MyNumber, ret,
993 nullUndef, target, recursive, obj,
994 defaults, defaultsCopy, options1, options1Copy, options2, options2Copy, merged2,
995 settings = { "xnumber1": 5, "xnumber2": 7, "xstring1": "peter", "xstring2": "pan" },
996 options = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
997 optionsCopy = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
998 merged = { "xnumber1": 5, "xnumber2": 1, "xstring1": "peter", "xstring2": "x", "xxx": "newstring" },
999 deep1 = { "foo": { "bar": true } },
1000 deep2 = { "foo": { "baz": true }, "foo2": document },
1001 deep2copy = { "foo": { "baz": true }, "foo2": document },
1002 deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document },
1004 nestedarray = { "arr": arr };
1006 jQuery.extend(settings, options);
1007 deepEqual( settings, merged, "Check if extended: settings must be extended" );
1008 deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
1010 jQuery.extend(settings, null, options);
1011 deepEqual( settings, merged, "Check if extended: settings must be extended" );
1012 deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
1014 jQuery.extend(true, deep1, deep2);
1015 deepEqual( deep1["foo"], deepmerged["foo"], "Check if foo: settings must be extended" );
1016 deepEqual( deep2["foo"], deep2copy["foo"], "Check if not deep2: options must not be modified" );
1017 equal( deep1["foo2"], document, "Make sure that a deep clone was not attempted on the document" );
1019 ok( jQuery.extend(true, {}, nestedarray)["arr"] !== arr, "Deep extend of object must clone child array" );
1022 ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array have to be an Array" );
1023 ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object have to be an plain object" );
1026 optionsWithLength = { "foo": { "length": -1 } };
1027 jQuery.extend(true, empty, optionsWithLength);
1028 deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" );
1031 optionsWithDate = { "foo": { "date": new Date() } };
1032 jQuery.extend(true, empty, optionsWithDate);
1033 deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" );
1036 myKlass = function() {};
1037 customObject = new myKlass();
1038 optionsWithCustomObject = { "foo": { "date": customObject } };
1040 jQuery.extend(true, empty, optionsWithCustomObject);
1041 ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" );
1043 // Makes the class a little more realistic
1044 myKlass.prototype = { "someMethod": function(){} };
1046 jQuery.extend(true, empty, optionsWithCustomObject);
1047 ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" );
1051 ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } );
1052 ok( parseInt(ret.foo, 10) === 5, "Wrapped numbers copy correctly" );
1055 nullUndef = jQuery.extend({}, options, { "xnumber2": null });
1056 ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied");
1058 nullUndef = jQuery.extend({}, options, { "xnumber2": undefined });
1059 ok( nullUndef["xnumber2"] === options["xnumber2"], "Check to make sure undefined values are not copied");
1061 nullUndef = jQuery.extend({}, options, { "xnumber0": null });
1062 ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted");
1065 recursive = { foo:target, bar:5 };
1066 jQuery.extend(true, target, recursive);
1067 deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
1069 ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
1070 equal( ret.foo.length, 1, "Check to make sure a value with coercion 'false' copies over when necessary to fix #1907" );
1072 ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
1073 ok( typeof ret.foo !== "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" );
1075 ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
1076 ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
1079 jQuery.extend(true, obj, { foo:"notnull" } );
1080 equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
1083 jQuery.extend(func, { key: "value" } );
1084 equal( func.key, "value", "Verify a function can be extended" );
1086 defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1087 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1088 options1 = { xnumber2: 1, xstring2: "x" };
1089 options1Copy = { xnumber2: 1, xstring2: "x" };
1090 options2 = { xstring2: "xx", xxx: "newstringx" };
1091 options2Copy = { xstring2: "xx", xxx: "newstringx" };
1092 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
1094 settings = jQuery.extend({}, defaults, options1, options2);
1095 deepEqual( settings, merged2, "Check if extended: settings must be extended" );
1096 deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
1097 deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
1098 deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
1101 test("jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed by object", function() {
1104 var result, initial = {
1105 // This will make "copyIsArray" true
1106 array: [ 1, 2, 3, 4 ],
1107 // If "copyIsArray" doesn't get reset to false, the check
1108 // will evaluate true and enter the array copy block
1109 // instead of the object copy block. Since the ternary in the
1110 // "copyIsArray" block will will evaluate to false
1111 // (check if operating on an array with ), this will be
1112 // replaced by an empty array.
1116 result = jQuery.extend( true, {}, initial );
1118 deepEqual( result, initial, "The [result] and [initial] have equal shape and values" );
1119 ok( !jQuery.isArray( result.object ), "result.object wasn't paved with an empty array" );
1122 test("jQuery.each(Object,Function)", function() {
1125 var i, label, seen, callback;
1128 jQuery.each( [ 3, 4, 5 ], function( k, v ) {
1131 deepEqual( seen, { "0": 3, "1": 4, "2": 5 }, "Array iteration" );
1134 jQuery.each( { name: "name", lang: "lang" }, function( k, v ) {
1137 deepEqual( seen, { name: "name", lang: "lang" }, "Object iteration" );
1140 jQuery.each( [ 1, 2, 3 ], function( k, v ) {
1146 deepEqual( seen, [ 1, 2 ] , "Broken array iteration" );
1149 jQuery.each( {"a": 1, "b": 2,"c": 3 }, function( k, v ) {
1153 deepEqual( seen, [ 1 ], "Broken object iteration" );
1156 Zero: function() {},
1157 One: function( a ) { a = a; },
1158 Two: function( a, b ) { a = a; b = b; }
1160 callback = function( k ) {
1161 equal( k, "foo", label + "-argument function treated like object" );
1165 seen[ i ].foo = "bar";
1166 jQuery.each( seen[ i ], callback );
1170 "undefined": undefined,
1175 "nonempty string": "string",
1176 "string \"0\"": "0",
1180 callback = function( k ) {
1181 equal( k, "length", "Object with " + label + " length treated like object" );
1185 jQuery.each( { length: seen[ i ] }, callback );
1189 "sparse Array": Array( 4 ),
1190 "length: 1 plain object": { length: 1, "0": true },
1191 "length: 2 plain object": { length: 2, "0": true, "1": true },
1192 NodeList: document.getElementsByTagName("html")
1194 callback = function( k ) {
1195 if ( seen[ label ] ) {
1196 delete seen[ label ];
1197 equal( k, "0", label + " treated like array" );
1203 jQuery.each( seen[ i ], callback );
1207 jQuery.each( { length: 0 }, function() {
1210 ok( !seen, "length: 0 plain object treated like array" );
1213 jQuery.each( document.getElementsByTagName("asdf"), function() {
1216 ok( !seen, "empty NodeList treated like array" );
1219 jQuery.each( document.styleSheets, function() {
1222 equal( i, 2, "Iteration over document.styleSheets" );
1225 test("jQuery.makeArray", function(){
1228 equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
1230 equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
1232 equal( (function() { return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
1234 equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
1236 equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
1238 equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
1240 equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
1242 equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
1244 equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
1246 equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
1248 ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
1250 // function, is tricky as it has length
1251 equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
1253 //window, also has length
1254 equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
1256 equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
1258 // Some nodes inherit traits of nodelists
1259 ok( jQuery.makeArray(document.getElementById("form")).length >= 13,
1260 "Pass makeArray a form (treat as elements)" );
1263 test("jQuery.inArray", function(){
1266 equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
1268 equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
1270 equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
1273 test("jQuery.isEmptyObject", function(){
1276 equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
1277 equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
1279 // What about this ?
1280 // equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
1283 test("jQuery.proxy", function(){
1286 var test2, test3, test4, fn, cb,
1287 test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); },
1288 thisObject = { foo: "bar", method: test };
1290 // Make sure normal works
1291 test.call( thisObject );
1294 jQuery.proxy( test, thisObject )();
1296 // Another take on it
1297 jQuery.proxy( thisObject, "method" )();
1299 // Make sure it doesn't freak out
1300 equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
1302 // Partial application
1303 test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
1304 jQuery.proxy( test2, null, "pre-applied" )();
1306 // Partial application w/ normal arguments
1307 test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
1308 jQuery.proxy( test3, null, "pre-applied" )( "normal" );
1311 test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
1312 jQuery.proxy( test4, "meth" )( "boom" );
1314 // jQuery 1.9 improved currying with `this` object
1316 equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
1317 equal( this.foo, "bar", "this-object passed" );
1319 cb = jQuery.proxy( fn, null, "arg1", "arg2" );
1320 cb.call( thisObject, "arg3" );
1323 test("jQuery.parseHTML", function() {
1328 equal( jQuery.parseHTML(), null, "Nothing in, null out." );
1329 equal( jQuery.parseHTML( null ), null, "Null in, null out." );
1330 equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
1332 jQuery.parseHTML( "<div></div>", document.getElementById("form") );
1333 }, "Passing an element as the context raises an exception (context should be a document)");
1335 nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML );
1336 ok( nodes.length > 4, "Parse a large html string" );
1337 equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
1339 html = "<script>undefined()</script>";
1340 equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
1341 equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
1343 html += "<div></div>";
1344 equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
1345 equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve script position");
1347 equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" );
1348 equal( jQuery.parseHTML( "\t<div></div>" )[0].nodeValue, "\t", "Preserve leading whitespace" );
1350 equal( jQuery.parseHTML(" <div/> ")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
1352 html = jQuery.parseHTML( "<div>test div</div>" );
1354 equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
1355 equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" );
1357 equal( jQuery.parseHTML("<span><span>").length, 1, "Incorrect html-strings should not break anything" );
1358 equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11,
1359 "parentNode should be documentFragment for wrapMap (variable in manipulation module) elements too" );
1360 ok( jQuery.parseHTML("<#if><tr><p>This is a test.</p></tr><#/if>") || true, "Garbage input should not cause error" );
1363 test("jQuery.parseJSON", function() {
1366 strictEqual( jQuery.parseJSON( null ), null, "primitive null" );
1367 strictEqual( jQuery.parseJSON("0.88"), 0.88, "Number" );
1369 jQuery.parseJSON("\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \""),
1370 " \" \\ / \b \f \n \r \t ~ \u263A ",
1373 deepEqual( jQuery.parseJSON("{}"), {}, "Empty object" );
1374 deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object" );
1375 deepEqual( jQuery.parseJSON("[0]"), [ 0 ], "Simple array" );
1378 jQuery.parseJSON("[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]"),
1379 [ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ],
1380 "Array of all data types"
1383 jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," +
1384 "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }"),
1385 { string: "", number: 42, object: {}, array: [[]], boolean: [ true, false ], "null": null },
1386 "Dictionary of all data types"
1389 deepEqual( jQuery.parseJSON("\n{\"test\":1}\t"), { "test": 1 },
1390 "Leading and trailing whitespace are ignored" );
1394 }, null, "Undefined raises an error" );
1396 jQuery.parseJSON( "" );
1397 }, null, "Empty string raises an error" );
1399 jQuery.parseJSON("''");
1400 }, null, "Single-quoted string raises an error" );
1405 jQuery.parseJSON("\" \\a \"");
1406 }, null, "Invalid string escape raises an error" );
1408 // Broken on IE8, Safari 5.1 Windows
1410 jQuery.parseJSON("\"\t\"");
1411 }, null, "Unescaped control character raises an error" );
1415 jQuery.parseJSON(".123");
1416 }, null, "Number with no integer component raises an error" );
1420 var result = jQuery.parseJSON("0101");
1423 // Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers
1424 if ( result === 101 ) {
1425 throw new Error("close enough");
1427 }, null, "Leading-zero number raises an error or is parsed as decimal" );
1429 jQuery.parseJSON("{a:1}");
1430 }, null, "Unquoted property raises an error" );
1432 jQuery.parseJSON("{'a':1}");
1433 }, null, "Single-quoted property raises an error" );
1435 jQuery.parseJSON("[,]");
1436 }, null, "Array element elision raises an error" );
1438 jQuery.parseJSON("{},[]");
1439 }, null, "Comma expression raises an error" );
1441 jQuery.parseJSON("[]\n,{}");
1442 }, null, "Newline-containing comma expression raises an error" );
1444 jQuery.parseJSON("\"\"\n\"\"");
1445 }, null, "Automatic semicolon insertion raises an error" );
1447 strictEqual( jQuery.parseJSON([ 0 ]), 0, "Input cast to string" );
1450 test("jQuery.parseXML", 8, function(){
1453 xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" );
1454 tmp = xml.getElementsByTagName( "p" )[ 0 ];
1455 ok( !!tmp, "<p> present in document" );
1456 tmp = tmp.getElementsByTagName( "b" )[ 0 ];
1457 ok( !!tmp, "<b> present in document" );
1458 strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" );
1460 strictEqual( e, undefined, "unexpected error" );
1463 xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" );
1464 ok( false, "invalid xml not detected" );
1466 strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" );
1469 xml = jQuery.parseXML( "" );
1470 strictEqual( xml, null, "empty string => null document" );
1471 xml = jQuery.parseXML();
1472 strictEqual( xml, null, "undefined string => null document" );
1473 xml = jQuery.parseXML( null );
1474 strictEqual( xml, null, "null string => null document" );
1475 xml = jQuery.parseXML( true );
1476 strictEqual( xml, null, "non-string => null document" );
1478 ok( false, "empty input throws exception" );
1482 test("jQuery.camelCase()", function() {
1485 "foo-bar": "fooBar",
1486 "foo-bar-baz": "fooBarBaz",
1487 "girl-u-want": "girlUWant",
1488 "the-4th-dimension": "the4thDimension",
1489 "-o-tannenbaum": "OTannenbaum",
1490 "-moz-illa": "MozIlla",
1491 "-ms-take": "msTake"
1496 jQuery.each( tests, function( key, val ) {
1497 equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
1501 testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
1503 ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
1504 deepEqual( errors, [], "No errors" );
1505 ok( $(), "jQuery executes" );
1508 // iOS7 doesn't fire the load event if the long-loading iframe gets its source reset to about:blank.
1509 // This makes this test fail but it doesn't seem to cause any real-life problems so blacklisting
1510 // this test there is preferred to complicating the hard-to-test core/ready code further.
1511 if ( !/iphone os 7_/i.test( navigator.userAgent ) ) {
1512 testIframeWithCallback( "document ready when jQuery loaded asynchronously (#13655)", "core/dynamic_ready.html", function( ready ) {
1514 equal( true, ready, "document ready correctly fired when jQuery is loaded after DOMContentLoaded" );
1518 testIframeWithCallback( "Tolerating alias-masked DOM properties (#14074)", "core/aliased.html",
1519 function( errors ) {
1521 deepEqual( errors, [], "jQuery loaded" );
1525 testIframeWithCallback( "Don't call window.onready (#14802)", "core/onready.html",
1528 equal( error, false, "no call to user-defined onready" );