1 module("core", { teardown: moduleTeardown });
3 test("Basic requirements", function() {
5 ok( Array.prototype.push, "Array.push()" );
6 ok( Function.prototype.apply, "Function.apply()" );
7 ok( document.getElementById, "getElementById" );
8 ok( document.getElementsByTagName, "getElementsByTagName" );
9 ok( RegExp, "RegExp" );
10 ok( jQuery, "jQuery" );
14 test("jQuery()", function() {
18 code = jQuery("<code/>"),
19 img = jQuery("<img/>"),
20 div = jQuery("<div/><hr/><code/><b/>"),
30 // The $(html, props) signature can stealth-call any $.fn method, check for a
31 // few here but beware of modular builds where these methods may be excluded.
32 if ( jQuery.fn.click ) {
34 attrObj["click"] = function() { ok( exec, "Click executed." ); };
36 if ( jQuery.fn.width ) {
38 attrObj["width"] = 10;
40 if ( jQuery.fn.offset ) {
42 attrObj["offset"] = { "top": 1, "left": 1 };
44 if ( jQuery.fn.css ) {
46 attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
48 if ( jQuery.fn.attr ) {
50 attrObj.attr = { "desired": "very" };
55 // Basic constructor's behavior
56 equal( jQuery().length, 0, "jQuery() === jQuery([])" );
57 equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
58 equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
59 equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
60 equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
62 equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
64 // can actually yield more than one, when iframes are included, the window is an array as well
65 equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
68 // disabled since this test was doing nothing. i tried to fix it but i'm not sure
69 // what the expected behavior should even be. FF returns "\n" for the text node
70 // make sure this is handled
71 var crlfContainer = jQuery('<p>\r\n</p>');
72 var x = crlfContainer.contents().get(0).nodeValue;
73 equal( x, what???, "Check for \\r and \\n in jQuery()" );
76 /* // Disabled until we add this functionality in
79 jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
83 ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
85 equal( code.length, 1, "Correct number of elements generated for code" );
86 equal( code.parent().length, 0, "Make sure that the generated HTML has no parent." );
88 equal( img.length, 1, "Correct number of elements generated for img" );
89 equal( img.parent().length, 0, "Make sure that the generated HTML has no parent." );
91 equal( div.length, 4, "Correct number of elements generated for div hr code b" );
92 equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
94 equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
96 equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
98 elem = jQuery(" <em>hello</em>")[0];
99 equal( elem.nodeName.toLowerCase(), "em", "leading space" );
101 elem = jQuery("\n\n<em>world</em>")[0];
102 equal( elem.nodeName.toLowerCase(), "em", "leading newlines" );
104 elem = jQuery("<div/>", attrObj );
106 if ( jQuery.fn.width ) {
107 equal( elem[0].style.width, "10px", "jQuery() quick setter width");
110 if ( jQuery.fn.offset ) {
111 equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
114 if ( jQuery.fn.css ) {
115 equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
116 equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
119 if ( jQuery.fn.attr ) {
120 equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
123 equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
124 equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
125 equal( elem[0].className, "test2", "jQuery() quick setter class");
126 equal( elem[0].id, "test3", "jQuery() quick setter id");
129 elem.trigger("click");
131 // manually clean up detached elements
134 for ( i = 0; i < 3; ++i ) {
135 elem = jQuery("<input type='text' value='TEST' />");
137 equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
139 // manually clean up detached elements
142 for ( i = 0; i < 128; i++ ) {
147 test("jQuery(selector, context)", function() {
149 deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
150 deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
151 deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
154 test( "selector state", function() {
159 test = jQuery( undefined );
160 equal( test.selector, "", "Empty jQuery Selector" );
161 equal( test.context, undefined, "Empty jQuery Context" );
163 test = jQuery( document );
164 equal( test.selector, "", "Document Selector" );
165 equal( test.context, document, "Document Context" );
167 test = jQuery( document.body );
168 equal( test.selector, "", "Body Selector" );
169 equal( test.context, document.body, "Body Context" );
171 test = jQuery("#qunit-fixture");
172 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
173 equal( test.context, document, "#qunit-fixture Context" );
175 test = jQuery("#notfoundnono");
176 equal( test.selector, "#notfoundnono", "#notfoundnono Selector" );
177 equal( test.context, document, "#notfoundnono Context" );
179 test = jQuery( "#qunit-fixture", document );
180 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
181 equal( test.context, document, "#qunit-fixture Context" );
183 test = jQuery( "#qunit-fixture", document.body );
184 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
185 equal( test.context, document.body, "#qunit-fixture Context" );
188 test = jQuery( test );
189 equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
190 equal( test.context, document.body, "#qunit-fixture Context" );
192 test = jQuery( document.body ).find("#qunit-fixture");
193 equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
194 equal( test.context, document.body, "#qunit-fixture find Context" );
197 test( "globalEval", function() {
199 Globals.register("globalEvalTest");
201 jQuery.globalEval("globalEvalTest = 1;");
202 equal( window.globalEvalTest, 1, "Test variable assignments are global" );
204 jQuery.globalEval("var globalEvalTest = 2;");
205 equal( window.globalEvalTest, 2, "Test variable declarations are global" );
207 jQuery.globalEval("this.globalEvalTest = 3;");
208 equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
211 test( "globalEval execution after script injection (#7862)", 1, function() {
213 script = document.createElement( "script" );
215 script.src = "data/longLoadScript.php?sleep=2";
218 document.body.appendChild( script );
220 jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";");
221 ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
224 test("noConflict", function() {
229 strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
230 strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
231 strictEqual( window["$"], original$, "Make sure $ was reverted." );
235 strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
236 strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
237 strictEqual( window["$"], original$, "Make sure $ was reverted." );
238 ok( $$().pushStack([]), "Make sure that jQuery still works." );
240 window["jQuery"] = jQuery = $$;
243 test("trim", function() {
246 var nbsp = String.fromCharCode(160);
248 equal( jQuery.trim("hello "), "hello", "trailing space" );
249 equal( jQuery.trim(" hello"), "hello", "leading space" );
250 equal( jQuery.trim(" hello "), "hello", "space on both sides" );
251 equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " );
253 equal( jQuery.trim(), "", "Nothing in." );
254 equal( jQuery.trim( undefined ), "", "Undefined" );
255 equal( jQuery.trim( null ), "", "Null" );
256 equal( jQuery.trim( 5 ), "5", "Number" );
257 equal( jQuery.trim( false ), "false", "Boolean" );
259 equal( jQuery.trim(" "), "", "space should be trimmed" );
260 equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" );
261 equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" );
262 equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" );
265 test("type", function() {
268 equal( jQuery.type(null), "null", "null" );
269 equal( jQuery.type(undefined), "undefined", "undefined" );
270 equal( jQuery.type(true), "boolean", "Boolean" );
271 equal( jQuery.type(false), "boolean", "Boolean" );
272 equal( jQuery.type(Boolean(true)), "boolean", "Boolean" );
273 equal( jQuery.type(0), "number", "Number" );
274 equal( jQuery.type(1), "number", "Number" );
275 equal( jQuery.type(Number(1)), "number", "Number" );
276 equal( jQuery.type(""), "string", "String" );
277 equal( jQuery.type("a"), "string", "String" );
278 equal( jQuery.type(String("a")), "string", "String" );
279 equal( jQuery.type({}), "object", "Object" );
280 equal( jQuery.type(/foo/), "regexp", "RegExp" );
281 equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" );
282 equal( jQuery.type([1]), "array", "Array" );
283 equal( jQuery.type(new Date()), "date", "Date" );
284 equal( jQuery.type(new Function("return;")), "function", "Function" );
285 equal( jQuery.type(function(){}), "function", "Function" );
286 equal( jQuery.type(new Error()), "error", "Error" );
287 equal( jQuery.type(window), "object", "Window" );
288 equal( jQuery.type(document), "object", "Document" );
289 equal( jQuery.type(document.body), "object", "Element" );
290 equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
291 equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
293 // Avoid Lint complaints
294 var MyString = String,
298 equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" );
299 equal( jQuery.type(new MyNumber(1)), "number", "Number" );
300 equal( jQuery.type(new MyString("a")), "string", "String" );
301 equal( jQuery.type(new MyObject()), "object", "Object" );
304 asyncTest("isPlainObject", function() {
307 var pass, iframe, doc,
310 // The use case that we want to match
311 ok( jQuery.isPlainObject({}), "{}" );
313 // Not objects shouldn't be matched
314 ok( !jQuery.isPlainObject(""), "string" );
315 ok( !jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number" );
316 ok( !jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean" );
317 ok( !jQuery.isPlainObject(null), "null" );
318 ok( !jQuery.isPlainObject(undefined), "undefined" );
320 // Arrays shouldn't be matched
321 ok( !jQuery.isPlainObject([]), "array" );
323 // Instantiated objects shouldn't be matched
324 ok( !jQuery.isPlainObject(new Date()), "new Date" );
326 // Functions shouldn't be matched
327 ok( !jQuery.isPlainObject(fn), "fn" );
329 // Again, instantiated objects shouldn't be matched
330 ok( !jQuery.isPlainObject(new fn()), "new fn (no methods)" );
332 // Makes the function a little more realistic
333 // (and harder to detect, incidentally)
334 fn.prototype["someMethod"] = function(){};
336 // Again, instantiated objects shouldn't be matched
337 ok( !jQuery.isPlainObject(new fn()), "new fn" );
339 // Make it even harder to detect in IE < 9
347 ok( !jQuery.isPlainObject(new fn()), "fn (inherited and own properties)");
350 ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" );
353 ok( !jQuery.isPlainObject( window ), "window" );
357 jQuery.isPlainObject( window.location );
360 ok( pass, "Does not throw exceptions on host objects" );
362 // Objects from other windows should be matched
363 Globals.register("iframeDone");
364 window.iframeDone = function( otherObject, detail ) {
365 window.iframeDone = undefined;
366 iframe.parentNode.removeChild( iframe );
367 ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
372 iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
373 doc = iframe.contentDocument || iframe.contentWindow.document;
375 doc.write("<body onload='window.parent.iframeDone(Object);'>");
378 window.iframeDone( Object, "iframes not supported" );
382 test("isFunction", function() {
385 var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
387 // Make sure that false values return false
388 ok( !jQuery.isFunction(), "No Value" );
389 ok( !jQuery.isFunction( null ), "null Value" );
390 ok( !jQuery.isFunction( undefined ), "undefined Value" );
391 ok( !jQuery.isFunction( "" ), "Empty String Value" );
392 ok( !jQuery.isFunction( 0 ), "0 Value" );
395 // Safari uses "(Internal Function)"
396 ok( jQuery.isFunction(String), "String Function("+String+")" );
397 ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
398 ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
399 ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
401 // When stringified, this could be misinterpreted
403 ok( !jQuery.isFunction(mystr), "Function String" );
405 // When stringified, this could be misinterpreted
406 myarr = [ "function" ];
407 ok( !jQuery.isFunction(myarr), "Function Array" );
409 // When stringified, this could be misinterpreted
410 myfunction = { "function": "test" };
411 ok( !jQuery.isFunction(myfunction), "Function Object" );
413 // Make sure normal functions still work
415 ok( jQuery.isFunction(fn), "Normal Function" );
417 obj = document.createElement("object");
419 // Firefox says this is a function
420 ok( !jQuery.isFunction(obj), "Object Element" );
422 // IE says this is an object
423 // Since 1.3, this isn't supported (#2968)
424 //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
426 nodes = document.body.childNodes;
428 // Safari says this is a function
429 ok( !jQuery.isFunction(nodes), "childNodes Property" );
431 first = document.body.firstChild;
433 // Normal elements are reported ok everywhere
434 ok( !jQuery.isFunction(first), "A normal DOM Element" );
436 input = document.createElement("input");
438 document.body.appendChild( input );
440 // IE says this is an object
441 // Since 1.3, this isn't supported (#2968)
442 //ok( jQuery.isFunction(input.focus), "A default function property" );
444 document.body.removeChild( input );
446 a = document.createElement("a");
447 a.href = "some-function";
448 document.body.appendChild( a );
450 // This serializes with the word 'function' in it
451 ok( !jQuery.isFunction(a), "Anchor Element" );
453 document.body.removeChild( a );
455 // Recursive function calls have lengths and array-like properties
456 function callme(callback){
457 function fn(response){
461 ok( jQuery.isFunction(fn), "Recursive Function Call" );
463 fn({ some: "data" });
467 callme(function(){});
471 test( "isNumeric", function() {
474 var t = jQuery.isNumeric,
475 ToString = function( value ) {
476 this.toString = function() {
477 return String( value );
481 ok( t( "-10" ), "Negative integer string" );
482 ok( t( "0" ), "Zero string" );
483 ok( t( "5" ), "Positive integer string" );
484 ok( t( -16 ), "Negative integer number" );
485 ok( t( 0 ), "Zero integer number" );
486 ok( t( 32 ), "Positive integer number" );
487 ok( t( "040" ), "Octal integer literal string" );
488 ok( t( "0xFF" ), "Hexadecimal integer literal string" );
489 ok( t( 0xFFF ), "Hexadecimal integer literal" );
490 ok( t( "-1.6" ), "Negative floating point string" );
491 ok( t( "4.536" ), "Positive floating point string" );
492 ok( t( -2.6 ), "Negative floating point number" );
493 ok( t( 3.1415 ), "Positive floating point number" );
494 ok( t( 1.5999999999999999 ), "Very precise floating point number" );
495 ok( t( 8e5 ), "Exponential notation" );
496 ok( t( "123e-2" ), "Exponential notation string" );
497 ok( t( new ToString( "42" ) ), "Custom .toString returning number" );
499 equal( t( "" ), false, "Empty string" );
500 equal( t( " " ), false, "Whitespace characters string" );
501 equal( t( "\t\t" ), false, "Tab characters string" );
502 equal( t( "abcdefghijklm1234567890" ), false, "Alphanumeric character string" );
503 equal( t( "xabcdefx" ), false, "Non-numeric character string" );
504 equal( t( true ), false, "Boolean true literal" );
505 equal( t( false ), false, "Boolean false literal" );
506 equal( t( "bcfed5.2" ), false, "Number with preceding non-numeric characters" );
507 equal( t( "7.2acdgs" ), false, "Number with trailling non-numeric characters" );
508 equal( t( undefined ), false, "Undefined value" );
509 equal( t( null ), false, "Null value" );
510 equal( t( NaN ), false, "NaN value" );
511 equal( t( Infinity ), false, "Infinity primitive" );
512 equal( t( Number.POSITIVE_INFINITY ), false, "Positive Infinity" );
513 equal( t( Number.NEGATIVE_INFINITY ), false, "Negative Infinity" );
514 equal( t( new ToString( "Devo" ) ), false, "Custom .toString returning non-number" );
515 equal( t( {} ), false, "Empty object" );
516 equal( t( [] ), false, "Empty array" );
517 equal( t( [ 42 ] ), false, "Array with one number" );
518 equal( t( function(){} ), false, "Instance of a function" );
519 equal( t( new Date() ), false, "Instance of a Date" );
522 test("isXMLDoc - HTML", function() {
525 ok( !jQuery.isXMLDoc( document ), "HTML document" );
526 ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" );
527 ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" );
530 iframe = document.createElement("iframe");
531 document.body.appendChild( iframe );
534 body = jQuery(iframe).contents()[0];
537 ok( !jQuery.isXMLDoc( body ), "Iframe body element" );
539 ok( false, "Iframe body element exception" );
543 ok( true, "Iframe body element - iframe not working correctly" );
546 document.body.removeChild( iframe );
549 test("XSS via location.hash", function() {
553 jQuery["_check9521"] = function(x){
554 ok( x, "script called from #id-like selector with inline handler" );
555 jQuery("#check9521").remove();
556 delete jQuery["_check9521"];
560 // This throws an error because it's processed like an id
561 jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo("#qunit-fixture");
563 jQuery["_check9521"](true);
567 test("isXMLDoc - XML", function() {
569 var xml = createDashboardXML();
570 ok( jQuery.isXMLDoc( xml ), "XML document" );
571 ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
572 ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
575 test("isWindow", function() {
578 ok( jQuery.isWindow(window), "window" );
579 ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
580 ok( !jQuery.isWindow(), "empty" );
581 ok( !jQuery.isWindow(null), "null" );
582 ok( !jQuery.isWindow(undefined), "undefined" );
583 ok( !jQuery.isWindow(document), "document" );
584 ok( !jQuery.isWindow(document.documentElement), "documentElement" );
585 ok( !jQuery.isWindow(""), "string" );
586 ok( !jQuery.isWindow(1), "number" );
587 ok( !jQuery.isWindow(true), "boolean" );
588 ok( !jQuery.isWindow({}), "object" );
589 ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
590 ok( !jQuery.isWindow(/window/), "regexp" );
591 ok( !jQuery.isWindow(function(){}), "function" );
594 test("jQuery('html')", function() {
599 jQuery["foo"] = false;
600 s = jQuery("<script>jQuery.foo='test';</script>")[0];
601 ok( s, "Creating a script" );
602 ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" );
603 jQuery("body").append("<script>jQuery.foo='test';</script>");
604 ok( jQuery["foo"], "Executing a scripts contents in the right context" );
606 // Test multi-line HTML
607 div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0];
608 equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." );
609 equal( div.firstChild.nodeType, 3, "Text node." );
610 equal( div.lastChild.nodeType, 3, "Text node." );
611 equal( div.childNodes[1].nodeType, 1, "Paragraph." );
612 equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." );
614 ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
616 ok( !jQuery("<script/>")[0].parentNode, "Create a script" );
618 ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." );
620 j = jQuery("<span>hi</span> there <!-- mon ami -->");
621 ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
623 ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
625 ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
626 ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
628 equal( jQuery( "element[attribute='<div></div>']" ).length, 0,
629 "When html is within brackets, do not recognize as html." );
630 //equal( jQuery( "element[attribute=<div></div>]" ).length, 0,
631 // "When html is within brackets, do not recognize as html." );
632 equal( jQuery( "element:not(<div></div>)" ).length, 0,
633 "When html is within parens, do not recognize as html." );
634 equal( jQuery( "\\<div\\>" ).length, 0, "Ignore escaped html characters" );
637 test("jQuery('massive html #7990')", function() {
641 li = "<li>very very very very large html string</li>",
644 for ( i = 0; i < 30000; i += 1 ) {
645 html[html.length] = li;
647 html[html.length] = "</ul>";
648 html = jQuery(html.join(""))[0];
649 equal( html.nodeName.toLowerCase(), "ul");
650 equal( html.firstChild.nodeName.toLowerCase(), "li");
651 equal( html.childNodes.length, 30000 );
654 test("jQuery('html', context)", function() {
657 var $div = jQuery("<div/>")[0],
658 $span = jQuery("<span/>", $div);
659 equal($span.length, 1, "verify a span created with a div context works, #1763");
662 test("jQuery(selector, xml).text(str) - loaded via xml document", function() {
665 var xml = createDashboardXML(),
666 // tests for #1419 where ie was a problem
667 tab = jQuery("tab", xml).eq(0);
668 equal( tab.text(), "blabla", "verify initial text correct" );
670 equal( tab.text(), "newtext", "verify new text correct" );
673 test("end()", function() {
675 equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "check for end" );
676 ok( jQuery("#yahoo").end(), "check for end with nothing to end" );
678 var x = jQuery("#yahoo");
680 equal( "Yahoo", jQuery("#yahoo").text(), "check for non-destructive behaviour" );
683 test("length", function() {
685 equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
688 test("get()", function() {
690 deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
693 test("toArray()", function() {
695 deepEqual( jQuery("#qunit-fixture p").toArray(),
696 q("firstp","ap","sndp","en","sap","first"),
697 "Convert jQuery object to an Array" );
700 test("inArray()", function() {
704 p: q("firstp", "sap", "ap", "first"),
705 em: q("siblingnext", "siblingfirst"),
706 div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"),
707 a: q("mark", "groups", "google", "simon1"),
711 p: { elem: jQuery("#ap")[0], index: 2 },
712 em: { elem: jQuery("#siblingfirst")[0], index: 1 },
713 div: { elem: jQuery("#nothiddendiv")[0], index: 1 },
714 a: { elem: jQuery("#simon1")[0], index: 3 }
717 p: jQuery("#liveSpan1")[0],
718 em: jQuery("#nothiddendiv")[0],
722 jQuery.each( tests, function( key, obj ) {
723 equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" );
724 // Third argument (fromIndex)
725 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" );
726 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" );
727 equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" );
730 jQuery.each( falseTests, function( key, elem ) {
731 equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" );
736 test("get(Number)", function() {
738 equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
739 strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
742 test("get(-Number)",function() {
744 equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
745 strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
748 test("each(Function)", function() {
753 div.each(function(){this.foo = "zoo";});
755 for ( i = 0; i < div.length; i++ ) {
756 if ( div.get(i).foo !== "zoo" ) {
760 ok( pass, "Execute a function, Relative" );
763 test("slice()", function() {
766 var $links = jQuery("#ap a");
768 deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" );
769 deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" );
770 deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" );
771 deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" );
773 deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" );
774 deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" );
775 deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" );
778 test("first()/last()", function() {
781 var $links = jQuery("#ap a"), $none = jQuery("asdf");
783 deepEqual( $links.first().get(), q("google"), "first()" );
784 deepEqual( $links.last().get(), q("mark"), "last()" );
786 deepEqual( $none.first().get(), [], "first() none" );
787 deepEqual( $none.last().get(), [], "last() none" );
790 test("map()", function() {
794 jQuery("#ap").map(function() {
795 return jQuery( this ).find("a").get();
797 q( "google", "groups", "anchor1", "mark" ),
802 jQuery("#ap > a").map(function() {
803 return this.parentNode;
810 test("jQuery.map", function() {
813 var i, label, result, callback;
815 result = jQuery.map( [ 3, 4, 5 ], function( v, k ) {
818 equal( result.join(""), "012", "Map the keys from an array" );
820 result = jQuery.map( [ 3, 4, 5 ], function( v ) {
823 equal( result.join(""), "345", "Map the values from an array" );
825 result = jQuery.map( { a: 1, b: 2 }, function( v, k ) {
828 equal( result.join(""), "ab", "Map the keys from an object" );
830 result = jQuery.map( { a: 1, b: 2 }, function( v ) {
833 equal( result.join(""), "12", "Map the values from an object" );
835 result = jQuery.map( [ "a", undefined, null, "b" ], function( v ) {
838 equal( result.join(""), "ab", "Array iteration does not include undefined/null results" );
840 result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v ) {
843 equal( result.join(""), "ab", "Object iteration does not include undefined/null results" );
847 One: function( a ) { a = a; },
848 Two: function( a, b ) { a = a; b = b; }
850 callback = function( v, k ) {
851 equal( k, "foo", label + "-argument function treated like object" );
853 for ( i in result ) {
855 result[ i ].foo = "bar";
856 jQuery.map( result[ i ], callback );
860 "undefined": undefined,
865 "nonempty string": "string",
870 callback = function( v, k ) {
871 equal( k, "length", "Object with " + label + " length treated like object" );
873 for ( i in result ) {
875 jQuery.map( { length: result[ i ] }, callback );
879 "sparse Array": Array( 4 ),
880 "length: 1 plain object": { length: 1, "0": true },
881 "length: 2 plain object": { length: 2, "0": true, "1": true },
882 NodeList: document.getElementsByTagName("html")
884 callback = function( v, k ) {
885 if ( result[ label ] ) {
886 delete result[ label ];
887 equal( k, "0", label + " treated like array" );
890 for ( i in result ) {
892 jQuery.map( result[ i ], callback );
896 jQuery.map( { length: 0 }, function() {
899 ok( !result, "length: 0 plain object treated like array" );
902 jQuery.map( document.getElementsByTagName("asdf"), function() {
905 ok( !result, "empty NodeList treated like array" );
907 result = jQuery.map( Array(4), function( v, k ){
908 return k % 2 ? k : [k,k,k];
910 equal( result.join(""), "00012223", "Array results flattened (#2616)" );
913 test("jQuery.merge()", function() {
917 jQuery.merge( [], [] ),
923 jQuery.merge( [ 1 ], [ 2 ] ),
925 "Basic (single-element)"
928 jQuery.merge( [ 1, 2 ], [ 3, 4 ] ),
930 "Basic (multiple-element)"
934 jQuery.merge( [ 1, 2 ], [] ),
939 jQuery.merge( [], [ 1, 2 ] ),
944 // Fixed at [5998], #3641
946 jQuery.merge( [ -2, -1 ], [ 0, 1, 2 ] ),
947 [ -2, -1 , 0, 1, 2 ],
948 "Second array including a zero (falsy)"
951 // After fixing #5527
953 jQuery.merge( [], [ null, undefined ] ),
955 "Second array including null and undefined values"
958 jQuery.merge( { length: 0 }, [ 1, 2 ] ),
959 { length: 2, 0: 1, 1: 2 },
963 jQuery.merge( [ 1, 2 ], { length: 1, 0: 3 } ),
969 jQuery.merge( [], document.getElementById("lengthtest").getElementsByTagName("input") ),
970 [ document.getElementById("length"), document.getElementById("idTest") ],
975 test("jQuery.grep()", function() {
978 var searchCriterion = function( value ) {
979 return value % 2 === 0;
982 deepEqual( jQuery.grep( [], searchCriterion ), [], "Empty array" );
983 deepEqual( jQuery.grep( new Array(4), searchCriterion ), [], "Sparse array" );
985 deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ), [ 2, 4, 6 ], "Satisfying elements present" );
986 deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion ), [], "Satisfying elements absent" );
988 deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ), [ 1, 3, 5 ], "Satisfying elements present and grep inverted" );
989 deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion, true ), [1, 3, 5, 7], "Satisfying elements absent and grep inverted" );
991 deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ), [ 2, 4, 6 ], "Satisfying elements present but grep explicitly uninverted" );
992 deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ), [], "Satisfying elements absent and grep explicitly uninverted" );
995 test("jQuery.extend(Object, Object)", function() {
998 var empty, optionsWithLength, optionsWithDate, myKlass,
999 customObject, optionsWithCustomObject, MyNumber, ret,
1000 nullUndef, target, recursive, obj,
1001 defaults, defaultsCopy, options1, options1Copy, options2, options2Copy, merged2,
1002 settings = { "xnumber1": 5, "xnumber2": 7, "xstring1": "peter", "xstring2": "pan" },
1003 options = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
1004 optionsCopy = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
1005 merged = { "xnumber1": 5, "xnumber2": 1, "xstring1": "peter", "xstring2": "x", "xxx": "newstring" },
1006 deep1 = { "foo": { "bar": true } },
1007 deep2 = { "foo": { "baz": true }, "foo2": document },
1008 deep2copy = { "foo": { "baz": true }, "foo2": document },
1009 deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document },
1011 nestedarray = { "arr": arr };
1013 jQuery.extend(settings, options);
1014 deepEqual( settings, merged, "Check if extended: settings must be extended" );
1015 deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
1017 jQuery.extend(settings, null, options);
1018 deepEqual( settings, merged, "Check if extended: settings must be extended" );
1019 deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
1021 jQuery.extend(true, deep1, deep2);
1022 deepEqual( deep1["foo"], deepmerged["foo"], "Check if foo: settings must be extended" );
1023 deepEqual( deep2["foo"], deep2copy["foo"], "Check if not deep2: options must not be modified" );
1024 equal( deep1["foo2"], document, "Make sure that a deep clone was not attempted on the document" );
1026 ok( jQuery.extend(true, {}, nestedarray)["arr"] !== arr, "Deep extend of object must clone child array" );
1029 ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array have to be an Array" );
1030 ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object have to be an plain object" );
1033 optionsWithLength = { "foo": { "length": -1 } };
1034 jQuery.extend(true, empty, optionsWithLength);
1035 deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" );
1038 optionsWithDate = { "foo": { "date": new Date() } };
1039 jQuery.extend(true, empty, optionsWithDate);
1040 deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" );
1043 myKlass = function() {};
1044 customObject = new myKlass();
1045 optionsWithCustomObject = { "foo": { "date": customObject } };
1047 jQuery.extend(true, empty, optionsWithCustomObject);
1048 ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" );
1050 // Makes the class a little more realistic
1051 myKlass.prototype = { "someMethod": function(){} };
1053 jQuery.extend(true, empty, optionsWithCustomObject);
1054 ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" );
1058 ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } );
1059 ok( parseInt(ret.foo, 10) === 5, "Wrapped numbers copy correctly" );
1062 nullUndef = jQuery.extend({}, options, { "xnumber2": null });
1063 ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied");
1065 nullUndef = jQuery.extend({}, options, { "xnumber2": undefined });
1066 ok( nullUndef["xnumber2"] === options["xnumber2"], "Check to make sure undefined values are not copied");
1068 nullUndef = jQuery.extend({}, options, { "xnumber0": null });
1069 ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted");
1072 recursive = { foo:target, bar:5 };
1073 jQuery.extend(true, target, recursive);
1074 deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
1076 ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
1077 equal( ret.foo.length, 1, "Check to make sure a value with coercion 'false' copies over when necessary to fix #1907" );
1079 ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
1080 ok( typeof ret.foo !== "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" );
1082 ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
1083 ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
1086 jQuery.extend(true, obj, { foo:"notnull" } );
1087 equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
1090 jQuery.extend(func, { key: "value" } );
1091 equal( func.key, "value", "Verify a function can be extended" );
1093 defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1094 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1095 options1 = { xnumber2: 1, xstring2: "x" };
1096 options1Copy = { xnumber2: 1, xstring2: "x" };
1097 options2 = { xstring2: "xx", xxx: "newstringx" };
1098 options2Copy = { xstring2: "xx", xxx: "newstringx" };
1099 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
1101 settings = jQuery.extend({}, defaults, options1, options2);
1102 deepEqual( settings, merged2, "Check if extended: settings must be extended" );
1103 deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
1104 deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
1105 deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
1108 test("jQuery.each(Object,Function)", function() {
1111 var i, label, seen, callback;
1114 jQuery.each( [ 3, 4, 5 ], function( k, v ) {
1117 deepEqual( seen, { "0": 3, "1": 4, "2": 5 }, "Array iteration" );
1120 jQuery.each( { name: "name", lang: "lang" }, function( k, v ) {
1123 deepEqual( seen, { name: "name", lang: "lang" }, "Object iteration" );
1126 jQuery.each( [ 1, 2, 3 ], function( k, v ) {
1132 deepEqual( seen, [ 1, 2 ] , "Broken array iteration" );
1135 jQuery.each( {"a": 1, "b": 2,"c": 3 }, function( k, v ) {
1139 deepEqual( seen, [ 1 ], "Broken object iteration" );
1142 Zero: function() {},
1143 One: function( a ) { a = a; },
1144 Two: function( a, b ) { a = a; b = b; }
1146 callback = function( k ) {
1147 equal( k, "foo", label + "-argument function treated like object" );
1151 seen[ i ].foo = "bar";
1152 jQuery.each( seen[ i ], callback );
1156 "undefined": undefined,
1161 "nonempty string": "string",
1162 "string \"0\"": "0",
1166 callback = function( k ) {
1167 equal( k, "length", "Object with " + label + " length treated like object" );
1171 jQuery.each( { length: seen[ i ] }, callback );
1175 "sparse Array": Array( 4 ),
1176 "length: 1 plain object": { length: 1, "0": true },
1177 "length: 2 plain object": { length: 2, "0": true, "1": true },
1178 NodeList: document.getElementsByTagName("html")
1180 callback = function( k ) {
1181 if ( seen[ label ] ) {
1182 delete seen[ label ];
1183 equal( k, "0", label + " treated like array" );
1189 jQuery.each( seen[ i ], callback );
1193 jQuery.each( { length: 0 }, function() {
1196 ok( !seen, "length: 0 plain object treated like array" );
1199 jQuery.each( document.getElementsByTagName("asdf"), function() {
1202 ok( !seen, "empty NodeList treated like array" );
1205 jQuery.each( document.styleSheets, function() {
1208 equal( i, 2, "Iteration over document.styleSheets" );
1211 test("jQuery.makeArray", function(){
1214 equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
1216 equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
1218 equal( (function() { return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
1220 equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
1222 equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
1224 equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
1226 equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
1228 equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
1230 equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
1232 equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
1234 ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
1236 // function, is tricky as it has length
1237 equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
1239 //window, also has length
1240 equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
1242 equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
1244 // Some nodes inherit traits of nodelists
1245 ok( jQuery.makeArray(document.getElementById("form")).length >= 13,
1246 "Pass makeArray a form (treat as elements)" );
1249 test("jQuery.inArray", function(){
1252 equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
1254 equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
1256 equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
1259 test("jQuery.isEmptyObject", function(){
1262 equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
1263 equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
1265 // What about this ?
1266 // equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
1269 test("jQuery.proxy", function(){
1272 var test2, test3, test4, fn, cb,
1273 test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); },
1274 thisObject = { foo: "bar", method: test };
1276 // Make sure normal works
1277 test.call( thisObject );
1280 jQuery.proxy( test, thisObject )();
1282 // Another take on it
1283 jQuery.proxy( thisObject, "method" )();
1285 // Make sure it doesn't freak out
1286 equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
1288 // Partial application
1289 test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
1290 jQuery.proxy( test2, null, "pre-applied" )();
1292 // Partial application w/ normal arguments
1293 test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
1294 jQuery.proxy( test3, null, "pre-applied" )( "normal" );
1297 test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
1298 jQuery.proxy( test4, "meth" )( "boom" );
1300 // jQuery 1.9 improved currying with `this` object
1302 equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
1303 equal( this.foo, "bar", "this-object passed" );
1305 cb = jQuery.proxy( fn, null, "arg1", "arg2" );
1306 cb.call( thisObject, "arg3" );
1309 test("jQuery.parseHTML", function() {
1314 equal( jQuery.parseHTML(), null, "Nothing in, null out." );
1315 equal( jQuery.parseHTML( null ), null, "Null in, null out." );
1316 equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
1318 jQuery.parseHTML( "<div></div>", document.getElementById("form") );
1319 }, "Passing an element as the context raises an exception (context should be a document)");
1321 nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML );
1322 ok( nodes.length > 4, "Parse a large html string" );
1323 equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
1325 html = "<script>undefined()</script>";
1326 equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
1327 equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
1329 html += "<div></div>";
1330 equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
1331 equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve script position");
1333 equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" );
1334 equal( jQuery.parseHTML( "\t<div></div>" )[0].nodeValue, "\t", "Preserve leading whitespace" );
1336 equal( jQuery.parseHTML(" <div/> ")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
1338 html = jQuery.parseHTML( "<div>test div</div>" );
1339 equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
1340 equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" );
1342 equal( jQuery.parseHTML("<span><span>").length, 1, "Incorrect html-strings should not break anything" );
1343 equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
1346 test("jQuery.parseJSON", function() {
1349 strictEqual( jQuery.parseJSON( null ), null, "primitive null" );
1350 strictEqual( jQuery.parseJSON("0.88"), 0.88, "Number" );
1352 jQuery.parseJSON("\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \""),
1353 " \" \\ / \b \f \n \r \t ~ \u263A ",
1356 deepEqual( jQuery.parseJSON("{}"), {}, "Empty object" );
1357 deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object" );
1358 deepEqual( jQuery.parseJSON("[0]"), [ 0 ], "Simple array" );
1361 jQuery.parseJSON("[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]"),
1362 [ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ],
1363 "Array of all data types"
1366 jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," +
1367 "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }"),
1368 { string: "", number: 42, object: {}, array: [[]], "boolean": [ true, false ], "null": null },
1369 "Dictionary of all data types"
1372 deepEqual( jQuery.parseJSON("\n{\"test\":1}\t"), { "test": 1 },
1373 "Leading and trailing whitespace are ignored" );
1377 }, null, "Undefined raises an error" );
1379 jQuery.parseJSON( "" );
1380 }, null, "Empty string raises an error" );
1382 jQuery.parseJSON("''");
1383 }, null, "Single-quoted string raises an error" );
1388 jQuery.parseJSON("\" \\a \"");
1389 }, null, "Invalid string escape raises an error" );
1391 // Broken on IE8, Safari 5.1 Windows
1393 jQuery.parseJSON("\"\t\"");
1394 }, null, "Unescaped control character raises an error" );
1398 jQuery.parseJSON(".123");
1399 }, null, "Number with no integer component raises an error" );
1403 var result = jQuery.parseJSON("0101");
1406 // Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers
1407 if ( result === 101 ) {
1408 throw new Error("close enough");
1410 }, null, "Leading-zero number raises an error or is parsed as decimal" );
1412 jQuery.parseJSON("{a:1}");
1413 }, null, "Unquoted property raises an error" );
1415 jQuery.parseJSON("{'a':1}");
1416 }, null, "Single-quoted property raises an error" );
1418 jQuery.parseJSON("[,]");
1419 }, null, "Array element elision raises an error" );
1421 jQuery.parseJSON("{},[]");
1422 }, null, "Comma expression raises an error" );
1424 jQuery.parseJSON("[]\n,{}");
1425 }, null, "Newline-containing comma expression raises an error" );
1427 jQuery.parseJSON("\"\"\n\"\"");
1428 }, null, "Automatic semicolon insertion raises an error" );
1430 strictEqual( jQuery.parseJSON([ 0 ]), 0, "Input cast to string" );
1433 test("jQuery.parseXML", 8, function(){
1436 xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" );
1437 tmp = xml.getElementsByTagName( "p" )[ 0 ];
1438 ok( !!tmp, "<p> present in document" );
1439 tmp = tmp.getElementsByTagName( "b" )[ 0 ];
1440 ok( !!tmp, "<b> present in document" );
1441 strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" );
1443 strictEqual( e, undefined, "unexpected error" );
1446 xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" );
1447 ok( false, "invalid xml not detected" );
1449 strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" );
1452 xml = jQuery.parseXML( "" );
1453 strictEqual( xml, null, "empty string => null document" );
1454 xml = jQuery.parseXML();
1455 strictEqual( xml, null, "undefined string => null document" );
1456 xml = jQuery.parseXML( null );
1457 strictEqual( xml, null, "null string => null document" );
1458 xml = jQuery.parseXML( true );
1459 strictEqual( xml, null, "non-string => null document" );
1461 ok( false, "empty input throws exception" );
1465 test("jQuery.camelCase()", function() {
1468 "foo-bar": "fooBar",
1469 "foo-bar-baz": "fooBarBaz",
1470 "girl-u-want": "girlUWant",
1471 "the-4th-dimension": "the4thDimension",
1472 "-o-tannenbaum": "OTannenbaum",
1473 "-moz-illa": "MozIlla",
1474 "-ms-take": "msTake"
1479 jQuery.each( tests, function( key, val ) {
1480 equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
1484 testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
1486 ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
1487 deepEqual( errors, [], "No errors" );
1488 ok( $(), "jQuery executes" );
1491 // iOS7 doesn't fire the load event if the long-loading iframe gets its source reset to about:blank.
1492 // This makes this test fail but it doesn't seem to cause any real-life problems so blacklisting
1493 // this test there is preferred to complicating the hard-to-test core/ready code further.
1494 if ( !/iphone os 7_/i.test( navigator.userAgent ) ) {
1495 testIframeWithCallback( "document ready when jQuery loaded asynchronously (#13655)", "core/dynamic_ready.html", function( ready ) {
1497 equal( true, ready, "document ready correctly fired when jQuery is loaded after DOMContentLoaded" );
1501 testIframeWithCallback( "Tolerating alias-masked DOM properties (#14074)", "core/aliased.html",
1502 function( errors ) {
1504 deepEqual( errors, [], "jQuery loaded" );
1508 testIframeWithCallback( "Don't call window.onready (#14802)", "core/onready.html",
1511 equal( error, false, "no call to user-defined onready" );