3 test("Basic requirements", function() {
\r
5 ok( Array.prototype.push, "Array.push()" );
\r
6 ok( Function.prototype.apply, "Function.apply()" );
\r
7 ok( document.getElementById, "getElementById" );
\r
8 ok( document.getElementsByTagName, "getElementsByTagName" );
\r
9 ok( RegExp, "RegExp" );
\r
10 ok( jQuery, "jQuery" );
\r
14 test("$()", function() {
\r
17 var main = $("#main");
\r
18 isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
\r
21 // disabled since this test was doing nothing. i tried to fix it but i'm not sure
\r
22 // what the expected behavior should even be. FF returns "\n" for the text node
\r
23 // make sure this is handled
\r
24 var crlfContainer = $('<p>\r\n</p>');
\r
25 var x = crlfContainer.contents().get(0).nodeValue;
\r
26 equals( x, what???, "Check for \\r and \\n in jQuery()" );
\r
29 /* // Disabled until we add this functionality in
\r
32 $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
\r
36 ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
\r
38 var code = $("<code/>");
\r
39 equals( code.length, 1, "Correct number of elements generated for code" );
\r
40 var img = $("<img/>");
\r
41 equals( img.length, 1, "Correct number of elements generated for img" );
\r
42 var div = $("<div/><hr/><code/><b/>");
\r
43 equals( div.length, 4, "Correct number of elements generated for div hr code b" );
\r
45 // can actually yield more than one, when iframes are included, the window is an array as well
\r
46 equals( $(window).length, 1, "Correct number of elements generated for window" );
\r
48 equals( $(document).length, 1, "Correct number of elements generated for document" );
\r
50 equals( $([1,2,3]).get(1), 2, "Test passing an array to the factory" );
\r
52 equals( $(document.body).get(0), $('body').get(0), "Test passing an html node to the factory" );
\r
55 test("browser", function() {
\r
59 "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0",
\r
60 "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0",
\r
62 * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0",
\r
64 //Browsers with Gecko engine
\r
66 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12",
\r
68 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3",
\r
70 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5",
\r
72 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11",
\r
74 "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
\r
75 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
\r
76 "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20",
\r
78 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
\r
79 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
\r
80 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
\r
81 //Other user agent string
\r
82 "Other browser's user agent 1.0":null
\r
84 for (var i in browsers) {
\r
85 var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
\r
86 version = v ? v[1] : null;
\r
87 equals( version, browsers[i], "Checking UA string" );
\r
91 test("noConflict", function() {
\r
95 var newjQuery = jQuery.noConflict();
\r
97 equals( newjQuery, old, "noConflict returned the jQuery object" );
\r
98 equals( jQuery, old, "Make sure jQuery wasn't touched." );
\r
99 equals( $, "$", "Make sure $ was reverted." );
\r
103 newjQuery = jQuery.noConflict(true);
\r
105 equals( newjQuery, old, "noConflict returned the jQuery object" );
\r
106 equals( jQuery, "jQuery", "Make sure jQuery was reverted." );
\r
107 equals( $, "$", "Make sure $ was reverted." );
\r
112 test("isFunction", function() {
\r
115 // Make sure that false values return false
\r
116 ok( !jQuery.isFunction(), "No Value" );
\r
117 ok( !jQuery.isFunction( null ), "null Value" );
\r
118 ok( !jQuery.isFunction( undefined ), "undefined Value" );
\r
119 ok( !jQuery.isFunction( "" ), "Empty String Value" );
\r
120 ok( !jQuery.isFunction( 0 ), "0 Value" );
\r
123 // Safari uses "(Internal Function)"
\r
124 ok( jQuery.isFunction(String), "String Function("+String+")" );
\r
125 ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
\r
126 ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
\r
127 ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
\r
129 // When stringified, this could be misinterpreted
\r
130 var mystr = "function";
\r
131 ok( !jQuery.isFunction(mystr), "Function String" );
\r
133 // When stringified, this could be misinterpreted
\r
134 var myarr = [ "function" ];
\r
135 ok( !jQuery.isFunction(myarr), "Function Array" );
\r
137 // When stringified, this could be misinterpreted
\r
138 var myfunction = { "function": "test" };
\r
139 ok( !jQuery.isFunction(myfunction), "Function Object" );
\r
141 // Make sure normal functions still work
\r
142 var fn = function(){};
\r
143 ok( jQuery.isFunction(fn), "Normal Function" );
\r
145 var obj = document.createElement("object");
\r
147 // Firefox says this is a function
\r
148 ok( !jQuery.isFunction(obj), "Object Element" );
\r
150 // IE says this is an object
\r
151 ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
\r
153 var nodes = document.body.childNodes;
\r
155 // Safari says this is a function
\r
156 ok( !jQuery.isFunction(nodes), "childNodes Property" );
\r
158 var first = document.body.firstChild;
\r
160 // Normal elements are reported ok everywhere
\r
161 ok( !jQuery.isFunction(first), "A normal DOM Element" );
\r
163 var input = document.createElement("input");
\r
164 input.type = "text";
\r
165 document.body.appendChild( input );
\r
167 // IE says this is an object
\r
168 ok( jQuery.isFunction(input.focus), "A default function property" );
\r
170 document.body.removeChild( input );
\r
172 var a = document.createElement("a");
\r
173 a.href = "some-function";
\r
174 document.body.appendChild( a );
\r
176 // This serializes with the word 'function' in it
\r
177 ok( !jQuery.isFunction(a), "Anchor Element" );
\r
179 document.body.removeChild( a );
\r
181 // Recursive function calls have lengths and array-like properties
\r
182 function callme(callback){
\r
183 function fn(response){
\r
184 callback(response);
\r
187 ok( jQuery.isFunction(fn), "Recursive Function Call" );
\r
189 fn({ some: "data" });
\r
193 callme(function(){});
\r
199 test("$('html')", function() {
\r
204 var s = $("<script>var foo='test';</script>")[0];
\r
205 ok( s, "Creating a script" );
\r
206 ok( !foo, "Make sure the script wasn't executed prematurely" );
\r
207 $("body").append(s);
\r
208 ok( foo, "Executing a scripts contents in the right context" );
\r
211 ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
\r
215 var j = $("<span>hi</span> there <!-- mon ami -->");
\r
216 ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
\r
218 ok( !$("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
\r
221 test("$('html', context)", function() {
\r
224 var $div = $("<div/>");
\r
225 var $span = $("<span/>", $div);
\r
226 equals($span.length, 1, "Verify a span created with a div context works, #1763");
\r
230 test("$(selector, xml).text(str) - Loaded via XML document", function() {
\r
233 $.get('data/dashboard.xml', function(xml) {
\r
234 // tests for #1419 where IE was a problem
\r
235 equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" );
\r
236 $("tab:first", xml).text("newtext");
\r
237 equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" );
\r
243 test("length", function() {
\r
245 equals( $("p").length, 6, "Get Number of Elements Found" );
\r
248 test("size()", function() {
\r
250 equals( $("p").size(), 6, "Get Number of Elements Found" );
\r
253 test("get()", function() {
\r
255 isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
\r
258 test("get(Number)", function() {
\r
260 equals( $("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
\r
263 test("add(String|Element|Array|undefined)", function() {
\r
265 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
266 isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
267 ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
\r
269 // For the time being, we're discontinuing support for $(form.elements) since it's ambiguous in IE
\r
270 // use $([]).add(form.elements) instead.
\r
271 //equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" );
\r
273 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
\r
274 equals( x[0].id, "x1", "Check on-the-fly element1" );
\r
275 equals( x[1].id, "x2", "Check on-the-fly element2" );
\r
277 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
278 equals( x[0].id, "x1", "Check on-the-fly element1" );
\r
279 equals( x[1].id, "x2", "Check on-the-fly element2" );
\r
282 equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
\r
284 // Added after #2811
\r
285 equals( $([]).add([window,document,document.body,document]).length, 3, "Pass an array" );
\r
286 equals( $(document).add(document).length, 1, "Check duplicated elements" );
\r
287 equals( $(window).add(window).length, 1, "Check duplicated elements using the window" );
\r
288 ok( $([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
\r
291 test("each(Function)", function() {
\r
293 var div = $("div");
\r
294 div.each(function(){this.foo = 'zoo';});
\r
296 for ( var i = 0; i < div.size(); i++ ) {
\r
297 if ( div.get(i).foo != "zoo" ) pass = false;
\r
299 ok( pass, "Execute a function, Relative" );
\r
302 test("index(Object)", function() {
\r
305 var elements = $([window, document]),
\r
306 inputElements = $('#radio1,#radio2,#check1,#check2');
\r
308 equals( elements.index(window), 0, "Check for index of elements" );
\r
309 equals( elements.index(document), 1, "Check for index of elements" );
\r
310 equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" );
\r
311 equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" );
\r
312 equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" );
\r
313 equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" );
\r
314 equals( inputElements.index(window), -1, "Check for not found index" );
\r
315 equals( inputElements.index(document), -1, "Check for not found index" );
\r
317 // enabled since [5500]
\r
318 equals( elements.index( elements ), 0, "Pass in a jQuery object" );
\r
319 equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
\r
322 test("attr(String)", function() {
\r
324 equals( $('#text1').attr('value'), "Test", 'Check for value attribute' );
\r
325 equals( $('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
\r
326 equals( $('#text1').attr('type'), "text", 'Check for type attribute' );
\r
327 equals( $('#radio1').attr('type'), "radio", 'Check for type attribute' );
\r
328 equals( $('#check1').attr('type'), "checkbox", 'Check for type attribute' );
\r
329 equals( $('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' );
\r
330 equals( $('#google').attr('title'), "Google!", 'Check for title attribute' );
\r
331 equals( $('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' );
\r
332 equals( $('#en').attr('lang'), "en", 'Check for lang attribute' );
\r
333 equals( $('#simon').attr('class'), "blog link", 'Check for class attribute' );
\r
334 equals( $('#name').attr('name'), "name", 'Check for name attribute' );
\r
335 equals( $('#text1').attr('name'), "action", 'Check for name attribute' );
\r
336 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
337 equals( $('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
\r
338 equals( $('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
\r
339 equals( $('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
\r
340 equals( $('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' );
\r
341 equals( $('#foo').attr('nodeName'), 'DIV', 'Check for nodeName attribute' );
\r
342 equals( $('#foo').attr('tagName'), 'DIV', 'Check for tagName attribute' );
\r
344 $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
\r
345 equals( $('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );
\r
349 test("attr(String) in XML Files", function() {
\r
352 $.get("data/dashboard.xml", function(xml) {
\r
353 equals( $("locations", xml).attr("class"), "foo", "Check class attribute in XML document" );
\r
354 equals( $("location", xml).attr("for"), "bar", "Check for attribute in XML document" );
\r
360 test("attr(String, Function)", function() {
\r
362 equals( $('#text1').attr('value', function() { return this.id })[0].value, "text1", "Set value from id" );
\r
363 equals( $('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index");
\r
366 test("attr(Hash)", function() {
\r
369 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
370 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
372 ok( pass, "Set Multiple Attributes" );
\r
375 test("attr(String, Object)", function() {
\r
377 var div = $("div").attr("foo", "bar");
\r
379 for ( var i = 0; i < div.size(); i++ ) {
\r
380 if ( div.get(i).getAttribute('foo') != "bar" ){
\r
385 equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
\r
387 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
\r
389 $("#name").attr('name', 'something');
\r
390 equals( $("#name").attr('name'), 'something', 'Set name attribute' );
\r
391 $("#check2").attr('checked', true);
\r
392 equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
\r
393 $("#check2").attr('checked', false);
\r
394 equals( document.getElementById('check2').checked, false, 'Set checked attribute' );
\r
395 $("#text1").attr('readonly', true);
\r
396 equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' );
\r
397 $("#text1").attr('readonly', false);
\r
398 equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' );
\r
399 $("#name").attr('maxlength', '5');
\r
400 equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' );
\r
401 $("#name").attr('maxLength', '10');
\r
402 equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
\r
405 $("#name").attr('someAttr', '0');
\r
406 equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
\r
407 $("#name").attr('someAttr', 0);
\r
408 equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
\r
409 $("#name").attr('someAttr', 1);
\r
410 equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
\r
412 // using contents will get comments regular, text, and comment nodes
\r
413 var j = $("#nonnodes").contents();
\r
415 j.attr("name", "attrvalue");
\r
416 equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
\r
417 j.removeAttr("name");
\r
421 var type = $("#check2").attr('type');
\r
422 var thrown = false;
\r
424 $("#check2").attr('type','hidden');
\r
428 ok( thrown, "Exception thrown when trying to change type property" );
\r
429 equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
\r
431 var check = document.createElement("input");
\r
434 $(check).attr('type','checkbox');
\r
438 ok( thrown, "Exception thrown when trying to change type property" );
\r
439 equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
\r
443 test("attr(String, Object) - Loaded via XML document", function() {
\r
446 $.get('data/dashboard.xml', function(xml) {
\r
448 $('tab', xml).each(function() {
\r
449 titles.push($(this).attr('title'));
\r
451 equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
\r
452 equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
\r
458 test("css(String|Hash)", function() {
\r
461 equals( $('#main').css("display"), 'none', 'Check for css property "display"');
\r
463 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
464 $('#foo').css({display: 'none'});
\r
465 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
466 $('#foo').css({display: 'block'});
\r
467 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
469 $('#floatTest').css({styleFloat: 'right'});
\r
470 equals( $('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
471 $('#floatTest').css({cssFloat: 'left'});
\r
472 equals( $('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
473 $('#floatTest').css({'float': 'right'});
\r
474 equals( $('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
\r
475 $('#floatTest').css({'font-size': '30px'});
\r
476 equals( $('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
478 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
479 $('#foo').css({opacity: n});
\r
480 equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
481 $('#foo').css({opacity: parseFloat(n)});
\r
482 equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
484 $('#foo').css({opacity: ''});
\r
485 equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
\r
488 test("css(String, Object)", function() {
\r
490 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
491 $('#foo').css('display', 'none');
\r
492 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
493 $('#foo').css('display', 'block');
\r
494 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
496 $('#floatTest').css('styleFloat', 'left');
\r
497 equals( $('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
498 $('#floatTest').css('cssFloat', 'right');
\r
499 equals( $('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
500 $('#floatTest').css('float', 'left');
\r
501 equals( $('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
\r
502 $('#floatTest').css('font-size', '20px');
\r
503 equals( $('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
505 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
506 $('#foo').css('opacity', n);
\r
507 equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
508 $('#foo').css('opacity', parseFloat(n));
\r
509 equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
511 $('#foo').css('opacity', '');
\r
512 equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
\r
513 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
\r
514 if (jQuery.browser.msie) {
\r
515 $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
\r
517 equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
\r
519 // using contents will get comments regular, text, and comment nodes
\r
520 var j = $("#nonnodes").contents();
\r
521 j.css("padding-left", "1px");
\r
522 equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
\r
524 // opera sometimes doesn't update 'display' correctly, see #2037
\r
525 $("#t2037")[0].innerHTML = $("#t2037")[0].innerHTML
\r
526 equals( $("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
\r
529 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
\r
532 var $checkedtest = $("#checkedtest");
\r
533 // IE6 was clearing "checked" in jQuery.css(elem, "height");
\r
534 jQuery.css($checkedtest[0], "height");
\r
535 ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
\r
536 ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
\r
537 ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
\r
538 ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
\r
541 test("width()", function() {
\r
544 var $div = $("#nothiddendiv");
\r
546 equals($div.width(), 30, "Test set to 30 correctly");
\r
547 $div.width(-1); // handle negative numbers by ignoring #1599
\r
548 equals($div.width(), 30, "Test negative width ignored");
\r
549 $div.css("padding", "20px");
\r
550 equals($div.width(), 30, "Test padding specified with pixels");
\r
551 $div.css("border", "2px solid #fff");
\r
552 equals($div.width(), 30, "Test border specified with pixels");
\r
553 $div.css("padding", "2em");
\r
554 equals($div.width(), 30, "Test padding specified with ems");
\r
555 $div.css("border", "1em solid #fff");
\r
556 equals($div.width(), 30, "Test border specified with ems");
\r
557 $div.css("padding", "2%");
\r
558 equals($div.width(), 30, "Test padding specified with percent");
\r
560 equals($div.width(), 30, "Test hidden div");
\r
562 $div.css({ display: "", border: "", padding: "" });
\r
564 $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
\r
565 equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding");
\r
566 $("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
\r
569 test("height()", function() {
\r
572 var $div = $("#nothiddendiv");
\r
574 equals($div.height(), 30, "Test set to 30 correctly");
\r
575 $div.height(-1); // handle negative numbers by ignoring #1599
\r
576 equals($div.height(), 30, "Test negative height ignored");
\r
577 $div.css("padding", "20px");
\r
578 equals($div.height(), 30, "Test padding specified with pixels");
\r
579 $div.css("border", "2px solid #fff");
\r
580 equals($div.height(), 30, "Test border specified with pixels");
\r
581 $div.css("padding", "2em");
\r
582 equals($div.height(), 30, "Test padding specified with ems");
\r
583 $div.css("border", "1em solid #fff");
\r
584 equals($div.height(), 30, "Test border specified with ems");
\r
585 $div.css("padding", "2%");
\r
586 equals($div.height(), 30, "Test padding specified with percent");
\r
588 equals($div.height(), 30, "Test hidden div");
\r
590 $div.css({ display: "", border: "", padding: "", height: "1px" });
\r
593 test("text()", function() {
\r
595 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
596 equals( $('#sap').text(), expected, 'Check for merged text of more then one element.' );
\r
599 test("wrap(String|Element)", function() {
\r
601 var defaultText = 'Try them out:'
\r
602 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
603 equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
\r
604 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
607 var defaultText = 'Try them out:'
\r
608 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
609 ok( result.is('ol'), 'Check for element wrapping' );
\r
610 equals( result.text(), defaultText, 'Check for element wrapping' );
\r
613 $('#check1').click(function() {
\r
614 var checkbox = this;
\r
615 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
616 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
\r
617 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
620 // using contents will get comments regular, text, and comment nodes
\r
621 var j = $("#nonnodes").contents();
\r
623 equals( $("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
\r
624 equals( $("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
\r
627 test("wrapAll(String|Element)", function() {
\r
629 var prev = $("#first")[0].previousSibling;
\r
630 var p = $("#first")[0].parentNode;
\r
631 var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
\r
632 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
\r
633 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
634 ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
635 equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
636 equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
\r
639 var prev = $("#first")[0].previousSibling;
\r
640 var p = $("#first")[0].parentNode;
\r
641 var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
\r
642 equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
\r
643 equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
644 equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
\r
647 test("wrapInner(String|Element)", function() {
\r
649 var num = $("#first").children().length;
\r
650 var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
\r
651 equals( $("#first").children().length, 1, "Only one child" );
\r
652 ok( $("#first").children().is(".red"), "Verify Right Element" );
\r
653 equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
\r
656 var num = $("#first").children().length;
\r
657 var result = $('#first').wrapInner(document.getElementById('empty'));
\r
658 equals( $("#first").children().length, 1, "Only one child" );
\r
659 ok( $("#first").children().is("#empty"), "Verify Right Element" );
\r
660 equals( $("#first").children().children().length, num, "Verify Elements Intact" );
\r
663 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
665 var defaultText = 'Try them out:'
\r
666 var result = $('#first').append('<b>buga</b>');
\r
667 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
\r
668 equals( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
\r
671 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
672 $('#sap').append(document.getElementById('first'));
\r
673 equals( expected, $('#sap').text(), "Check for appending of element" );
\r
676 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
677 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
678 equals( expected, $('#sap').text(), "Check for appending of array of elements" );
\r
681 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
682 $('#sap').append($("#first, #yahoo"));
\r
683 equals( expected, $('#sap').text(), "Check for appending of jQuery object" );
\r
686 $("#sap").append( 5 );
\r
687 ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
690 $("#sap").append( " text with spaces " );
\r
691 ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
\r
694 ok( $("#sap").append([]), "Check for appending an empty array." );
\r
695 ok( $("#sap").append(""), "Check for appending an empty string." );
\r
696 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
699 $("#sap").append(document.getElementById('form'));
\r
700 equals( $("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
\r
705 $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
\r
710 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
\r
713 $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
\r
714 t( 'Append legend', '#legend', ['legend'] );
\r
717 $('#select1').append('<OPTION>Test</OPTION>');
\r
718 equals( $('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
\r
720 $('#table').append('<colgroup></colgroup>');
\r
721 ok( $('#table colgroup').length, "Append colgroup" );
\r
723 $('#table colgroup').append('<col/>');
\r
724 ok( $('#table colgroup col').length, "Append col" );
\r
727 $('#table').append('<caption></caption>');
\r
728 ok( $('#table caption').length, "Append caption" );
\r
732 .append('<select id="appendSelect1"></select>')
\r
733 .append('<select id="appendSelect2"><option>Test</option></select>');
\r
735 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
\r
737 // using contents will get comments regular, text, and comment nodes
\r
738 var j = $("#nonnodes").contents();
\r
739 var d = $("<div/>").appendTo("#nonnodes").append(j);
\r
740 equals( $("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
\r
741 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
\r
742 d.contents().appendTo("#nonnodes");
\r
744 ok( $("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
\r
747 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
749 var defaultText = 'Try them out:'
\r
750 $('<b>buga</b>').appendTo('#first');
\r
751 equals( $("#first").text(), defaultText + 'buga', 'Check if text appending works' );
\r
752 equals( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
\r
755 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
756 $(document.getElementById('first')).appendTo('#sap');
\r
757 equals( expected, $('#sap').text(), "Check for appending of element" );
\r
760 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
761 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
762 equals( expected, $('#sap').text(), "Check for appending of array of elements" );
\r
765 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
766 $("#first, #yahoo").appendTo('#sap');
\r
767 equals( expected, $('#sap').text(), "Check for appending of jQuery object" );
\r
770 $('#select1').appendTo('#foo');
\r
771 t( 'Append select', '#foo select', ['select1'] );
\r
774 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
776 var defaultText = 'Try them out:'
\r
777 var result = $('#first').prepend('<b>buga</b>');
\r
778 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
\r
779 equals( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
\r
782 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
783 $('#sap').prepend(document.getElementById('first'));
\r
784 equals( expected, $('#sap').text(), "Check for prepending of element" );
\r
787 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
788 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
789 equals( expected, $('#sap').text(), "Check for prepending of array of elements" );
\r
792 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
793 $('#sap').prepend($("#first, #yahoo"));
\r
794 equals( expected, $('#sap').text(), "Check for prepending of jQuery object" );
\r
797 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
799 var defaultText = 'Try them out:'
\r
800 $('<b>buga</b>').prependTo('#first');
\r
801 equals( $('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
\r
802 equals( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
\r
805 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
806 $(document.getElementById('first')).prependTo('#sap');
\r
807 equals( expected, $('#sap').text(), "Check for prepending of element" );
\r
810 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
811 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
812 equals( expected, $('#sap').text(), "Check for prepending of array of elements" );
\r
815 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
816 $("#yahoo, #first").prependTo('#sap');
\r
817 equals( expected, $('#sap').text(), "Check for prepending of jQuery object" );
\r
820 $('<select id="prependSelect1"></select>').prependTo('form:last');
\r
821 $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
\r
823 t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
\r
826 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
828 var expected = 'This is a normal link: bugaYahoo';
\r
829 $('#yahoo').before('<b>buga</b>');
\r
830 equals( expected, $('#en').text(), 'Insert String before' );
\r
833 expected = "This is a normal link: Try them out:Yahoo";
\r
834 $('#yahoo').before(document.getElementById('first'));
\r
835 equals( expected, $('#en').text(), "Insert element before" );
\r
838 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
839 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
840 equals( expected, $('#en').text(), "Insert array of elements before" );
\r
843 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
844 $('#yahoo').before($("#first, #mark"));
\r
845 equals( expected, $('#en').text(), "Insert jQuery before" );
\r
848 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
850 var expected = 'This is a normal link: bugaYahoo';
\r
851 $('<b>buga</b>').insertBefore('#yahoo');
\r
852 equals( expected, $('#en').text(), 'Insert String before' );
\r
855 expected = "This is a normal link: Try them out:Yahoo";
\r
856 $(document.getElementById('first')).insertBefore('#yahoo');
\r
857 equals( expected, $('#en').text(), "Insert element before" );
\r
860 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
861 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
862 equals( expected, $('#en').text(), "Insert array of elements before" );
\r
865 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
866 $("#first, #mark").insertBefore('#yahoo');
\r
867 equals( expected, $('#en').text(), "Insert jQuery before" );
\r
870 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
872 var expected = 'This is a normal link: Yahoobuga';
\r
873 $('#yahoo').after('<b>buga</b>');
\r
874 equals( expected, $('#en').text(), 'Insert String after' );
\r
877 expected = "This is a normal link: YahooTry them out:";
\r
878 $('#yahoo').after(document.getElementById('first'));
\r
879 equals( expected, $('#en').text(), "Insert element after" );
\r
882 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
883 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
884 equals( expected, $('#en').text(), "Insert array of elements after" );
\r
887 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
888 $('#yahoo').after($("#first, #mark"));
\r
889 equals( expected, $('#en').text(), "Insert jQuery after" );
\r
892 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
894 var expected = 'This is a normal link: Yahoobuga';
\r
895 $('<b>buga</b>').insertAfter('#yahoo');
\r
896 equals( expected, $('#en').text(), 'Insert String after' );
\r
899 expected = "This is a normal link: YahooTry them out:";
\r
900 $(document.getElementById('first')).insertAfter('#yahoo');
\r
901 equals( expected, $('#en').text(), "Insert element after" );
\r
904 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
905 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
906 equals( expected, $('#en').text(), "Insert array of elements after" );
\r
909 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
910 $("#mark, #first").insertAfter('#yahoo');
\r
911 equals( expected, $('#en').text(), "Insert jQuery after" );
\r
914 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
\r
916 $('#yahoo').replaceWith('<b id="replace">buga</b>');
\r
917 ok( $("#replace")[0], 'Replace element with string' );
\r
918 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
921 $('#yahoo').replaceWith(document.getElementById('first'));
\r
922 ok( $("#first")[0], 'Replace element with element' );
\r
923 ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
926 $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
\r
927 ok( $("#first")[0], 'Replace element with array of elements' );
\r
928 ok( $("#mark")[0], 'Replace element with array of elements' );
\r
929 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
932 $('#yahoo').replaceWith($("#first, #mark"));
\r
933 ok( $("#first")[0], 'Replace element with set of elements' );
\r
934 ok( $("#mark")[0], 'Replace element with set of elements' );
\r
935 ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
938 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
\r
940 $('<b id="replace">buga</b>').replaceAll("#yahoo");
\r
941 ok( $("#replace")[0], 'Replace element with string' );
\r
942 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
945 $(document.getElementById('first')).replaceAll("#yahoo");
\r
946 ok( $("#first")[0], 'Replace element with element' );
\r
947 ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
950 $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
\r
951 ok( $("#first")[0], 'Replace element with array of elements' );
\r
952 ok( $("#mark")[0], 'Replace element with array of elements' );
\r
953 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
956 $("#first, #mark").replaceAll("#yahoo");
\r
957 ok( $("#first")[0], 'Replace element with set of elements' );
\r
958 ok( $("#mark")[0], 'Replace element with set of elements' );
\r
959 ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
962 test("end()", function() {
\r
964 equals( 'Yahoo', $('#yahoo').parent().end().text(), 'Check for end' );
\r
965 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
967 var x = $('#yahoo');
\r
969 equals( 'Yahoo', $('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
972 test("find(String)", function() {
\r
974 equals( 'Yahoo', $('#foo').find('.blogTest').text(), 'Check for find' );
\r
976 // using contents will get comments regular, text, and comment nodes
\r
977 var j = $("#nonnodes").contents();
\r
978 equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
\r
981 test("clone()", function() {
\r
983 equals( 'This is a normal link: Yahoo', $('#en').text(), 'Assert text for #en' );
\r
984 var clone = $('#yahoo').clone();
\r
985 equals( 'Try them out:Yahoo', $('#first').append(clone).text(), 'Check for clone' );
\r
986 equals( 'This is a normal link: Yahoo', $('#en').text(), 'Reassert text for #en' );
\r
989 "<table/>", "<tr/>", "<td/>", "<div/>",
\r
990 "<button/>", "<ul/>", "<ol/>", "<li/>",
\r
991 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
\r
992 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
\r
994 for (var i = 0; i < cloneTags.length; i++) {
\r
995 var j = $(cloneTags[i]);
\r
996 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
\r
999 // using contents will get comments regular, text, and comment nodes
\r
1000 var cl = $("#nonnodes").contents().clone();
\r
1001 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
\r
1005 test("clone() on XML nodes", function() {
\r
1008 $.get("data/dashboard.xml", function (xml) {
\r
1009 var root = $(xml.documentElement).clone();
\r
1010 $("tab:first", xml).text("origval");
\r
1011 $("tab:first", root).text("cloneval");
\r
1012 equals($("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
\r
1013 equals($("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
\r
1019 test("is(String)", function() {
\r
1021 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
1022 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
1023 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
1024 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
1025 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
1026 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
1027 ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
1028 ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
1029 ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
1030 ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
1031 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
1032 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
1033 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
1034 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
1035 ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
\r
1036 ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
\r
1037 ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
1038 ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
1039 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
1040 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
1041 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
1042 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
1044 // test is() with comma-seperated expressions
\r
1045 ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1046 ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1047 ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1048 ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1051 test("$.extend(Object, Object)", function() {
\r
1054 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1055 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1056 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1057 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
\r
1058 deep1 = { foo: { bar: true } },
\r
1059 deep1copy = { foo: { bar: true } },
\r
1060 deep2 = { foo: { baz: true }, foo2: document },
\r
1061 deep2copy = { foo: { baz: true }, foo2: document },
\r
1062 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
\r
1064 jQuery.extend(settings, options);
\r
1065 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1066 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1068 jQuery.extend(settings, null, options);
\r
1069 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1070 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1072 jQuery.extend(true, deep1, deep2);
\r
1073 isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
\r
1074 isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
\r
1075 equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
\r
1078 nullUndef = jQuery.extend({}, options, { xnumber2: null });
\r
1079 ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
\r
1081 nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
\r
1082 ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
\r
1084 nullUndef = jQuery.extend({}, options, { xnumber0: null });
\r
1085 ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
\r
1088 var recursive = { foo:target, bar:5 };
\r
1089 jQuery.extend(true, target, recursive);
\r
1090 isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
\r
1092 var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
\r
1093 equals( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
\r
1095 var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
\r
1096 ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
\r
1098 var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
\r
1099 ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
\r
1101 var obj = { foo:null };
\r
1102 jQuery.extend(true, obj, { foo:"notnull" } );
\r
1103 equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
\r
1105 function func() {}
\r
1106 jQuery.extend(func, { key: "value" } );
\r
1107 equals( func.key, "value", "Verify a function can be extended" );
\r
1109 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1110 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1111 options1 = { xnumber2: 1, xstring2: "x" },
\r
1112 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
1113 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
1114 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
1115 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
1117 var settings = jQuery.extend({}, defaults, options1, options2);
\r
1118 isObj( settings, merged2, "Check if extended: settings must be extended" );
\r
1119 isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
1120 isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
1121 isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
1124 test("val()", function() {
\r
1126 equals( $("#text1").val(), "Test", "Check for value of input element" );
\r
1127 equals( !$("#text1").val(), "", "Check for value of input element" );
\r
1128 // ticket #1714 this caused a JS error in IE
\r
1129 equals( $("#first").val(), "", "Check a paragraph element to see if it has a value" );
\r
1130 ok( $([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
\r
1133 test("val(String)", function() {
\r
1135 document.getElementById('text1').value = "bla";
\r
1136 equals( $("#text1").val(), "bla", "Check for modified value of input element" );
\r
1137 $("#text1").val('test');
\r
1138 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
1140 $("#select1").val("3");
\r
1141 equals( $("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
\r
1143 // using contents will get comments regular, text, and comment nodes
\r
1144 var j = $("#nonnodes").contents();
\r
1146 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
\r
1147 j.removeAttr("value");
\r
1150 var scriptorder = 0;
\r
1152 test("html(String)", function() {
\r
1154 var div = $("#main > div");
\r
1155 div.html("<b>test</b>");
\r
1157 for ( var i = 0; i < div.size(); i++ ) {
\r
1158 if ( div.get(i).childNodes.length != 1 ) pass = false;
\r
1160 ok( pass, "Set HTML" );
\r
1163 // using contents will get comments regular, text, and comment nodes
\r
1164 var j = $("#nonnodes").contents();
\r
1165 j.html("<b>bold</b>");
\r
1167 // this is needed, or the expando added by jQuery unique will yield a different html
\r
1168 j.find('b').removeData();
\r
1169 equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
\r
1171 $("#main").html("<select/>");
\r
1172 $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
\r
1173 equals( $("#main select").val(), "O2", "Selected option correct" );
\r
1177 $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
\r
1179 $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
\r
1181 // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
\r
1182 $("#main").html("<script>equals(scriptorder++, 0, 'Script is executed in order');equals($('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(scriptorder++, 1, 'Script (nested) is executed in order');equals($('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(scriptorder++, 2, 'Script (unnested) is executed in order');equals($('#scriptorder').length, 1,'Execute after html')<\/script>");
\r
1184 setTimeout( start, 100 );
\r
1187 test("filter()", function() {
\r
1189 isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
1190 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
1191 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
1192 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
1194 // using contents will get comments regular, text, and comment nodes
\r
1195 var j = $("#nonnodes").contents();
\r
1196 equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
\r
1197 equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
\r
1200 test("not()", function() {
\r
1202 equals( $("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
\r
1203 equals( $("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
\r
1204 isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
\r
1205 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
1206 isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
\r
1207 equals( $("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
\r
1208 isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
\r
1210 var selects = $("#form select");
\r
1211 isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
\r
1214 test("andSelf()", function() {
\r
1216 isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
\r
1217 isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
\r
1218 isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
\r
1219 isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
\r
1222 test("siblings([String])", function() {
\r
1224 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
1225 isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
1226 isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
1227 isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
\r
1228 isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
\r
1231 test("children([String])", function() {
\r
1233 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
1234 isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
\r
1235 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
1238 test("parent([String])", function() {
\r
1240 equals( $("#groups").parent()[0].id, "ap", "Simple parent check" );
\r
1241 equals( $("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
\r
1242 equals( $("#groups").parent("div").length, 0, "Filtered parent check, no match" );
\r
1243 equals( $("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
\r
1244 isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
\r
1247 test("parents([String])", function() {
\r
1249 equals( $("#groups").parents()[0].id, "ap", "Simple parents check" );
\r
1250 equals( $("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
\r
1251 equals( $("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
\r
1252 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
1253 isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
\r
1256 test("next([String])", function() {
\r
1258 equals( $("#ap").next()[0].id, "foo", "Simple next check" );
\r
1259 equals( $("#ap").next("div")[0].id, "foo", "Filtered next check" );
\r
1260 equals( $("#ap").next("p").length, 0, "Filtered next check, no match" );
\r
1261 equals( $("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
\r
1264 test("prev([String])", function() {
\r
1266 equals( $("#foo").prev()[0].id, "ap", "Simple prev check" );
\r
1267 equals( $("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
\r
1268 equals( $("#foo").prev("div").length, 0, "Filtered prev check, no match" );
\r
1269 equals( $("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
\r
1272 test("show()", function() {
\r
1274 var pass = true, div = $("div");
\r
1275 div.show().each(function(){
\r
1276 if ( this.style.display == "none" ) pass = false;
\r
1278 ok( pass, "Show" );
\r
1280 $("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
\r
1285 "code" : "inline",
\r
1287 "span" : "inline",
\r
1288 "table" : $.browser.msie ? "block" : "table",
\r
1289 "thead" : $.browser.msie ? "block" : "table-header-group",
\r
1290 "tbody" : $.browser.msie ? "block" : "table-row-group",
\r
1291 "tr" : $.browser.msie ? "block" : "table-row",
\r
1292 "th" : $.browser.msie ? "block" : "table-cell",
\r
1293 "td" : $.browser.msie ? "block" : "table-cell",
\r
1295 "li" : $.browser.msie ? "block" : "list-item"
\r
1298 $.each(test, function(selector, expected) {
\r
1299 var elem = $(selector, "#show-tests").show();
\r
1300 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
\r
1304 test("addClass(String)", function() {
\r
1306 var div = $("div");
\r
1307 div.addClass("test");
\r
1309 for ( var i = 0; i < div.size(); i++ ) {
\r
1310 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
1312 ok( pass, "Add Class" );
\r
1314 // using contents will get regular, text, and comment nodes
\r
1315 var j = $("#nonnodes").contents();
\r
1316 j.addClass("asdf");
\r
1317 ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
\r
1320 test("removeClass(String) - simple", function() {
\r
1322 var div = $("div").addClass("test").removeClass("test"),
\r
1324 for ( var i = 0; i < div.size(); i++ ) {
\r
1325 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
1327 ok( pass, "Remove Class" );
\r
1330 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
1331 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
1333 for ( var i = 0; i < div.size(); i++ ) {
\r
1334 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
1336 ok( pass, "Remove multiple classes" );
\r
1339 var div = $("div:eq(0)").addClass("test").removeClass("");
\r
1340 ok( div.is('.test'), "Empty string passed to removeClass" );
\r
1342 // using contents will get regular, text, and comment nodes
\r
1343 var j = $("#nonnodes").contents();
\r
1344 j.removeClass("asdf");
\r
1345 ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
\r
1348 test("toggleClass(String)", function() {
\r
1350 var e = $("#firstp");
\r
1351 ok( !e.is(".test"), "Assert class not present" );
\r
1352 e.toggleClass("test");
\r
1353 ok( e.is(".test"), "Assert class present" );
\r
1354 e.toggleClass("test");
\r
1355 ok( !e.is(".test"), "Assert class not present" );
\r
1358 test("removeAttr(String", function() {
\r
1360 equals( $('#mark').removeAttr("class")[0].className, "", "remove class" );
\r
1363 test("text(String)", function() {
\r
1365 equals( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML, "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
1367 // using contents will get comments regular, text, and comment nodes
\r
1368 var j = $("#nonnodes").contents();
\r
1370 equals( $(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
\r
1371 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
\r
1372 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
\r
1375 test("$.each(Object,Function)", function() {
\r
1377 $.each( [0,1,2], function(i, n){
\r
1378 equals( i, n, "Check array iteration" );
\r
1381 $.each( [5,6,7], function(i, n){
\r
1382 equals( i, n - 5, "Check array iteration" );
\r
1385 $.each( { name: "name", lang: "lang" }, function(i, n){
\r
1386 equals( i, n, "Check object iteration" );
\r
1390 jQuery.each([1,2,3], function(i,v){ total += v; });
\r
1391 equals( total, 6, "Looping over an array" );
\r
1393 jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
\r
1394 equals( total, 3, "Looping over an array, with break" );
\r
1396 jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
\r
1397 equals( total, 6, "Looping over an object" );
\r
1399 jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
\r
1400 equals( total, 3, "Looping over an object, with break" );
\r
1403 test("$.prop", function() {
\r
1405 var handle = function() { return this.id };
\r
1406 equals( $.prop($("#ap")[0], handle), "ap", "Check with Function argument" );
\r
1407 equals( $.prop($("#ap")[0], "value"), "value", "Check with value argument" );
\r
1410 test("$.className", function() {
\r
1412 var x = $("<p>Hi</p>")[0];
\r
1413 var c = $.className;
\r
1415 equals( x.className, "hi", "Check single added class" );
\r
1416 c.add(x, "foo bar");
\r
1417 equals( x.className, "hi foo bar", "Check more added classes" );
\r
1419 equals( x.className, "", "Remove all classes" );
\r
1420 c.add(x, "hi foo bar");
\r
1421 c.remove(x, "foo");
\r
1422 equals( x.className, "hi bar", "Check removal of one class" );
\r
1423 ok( c.has(x, "hi"), "Check has1" );
\r
1424 ok( c.has(x, "bar"), "Check has2" );
\r
1427 test("$.data", function() {
\r
1429 var div = $("#foo")[0];
\r
1430 equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
\r
1431 jQuery.data(div, "test", "success");
\r
1432 equals( jQuery.data(div, "test"), "success", "Check for added data" );
\r
1433 jQuery.data(div, "test", "overwritten");
\r
1434 equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );
\r
1435 jQuery.data(div, "test", undefined);
\r
1436 equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");
\r
1437 jQuery.data(div, "test", null);
\r
1438 ok( jQuery.data(div, "test") === null, "Check for null data");
\r
1441 test(".data()", function() {
\r
1443 var div = $("#foo");
\r
1444 equals( div.data("test"), undefined, "Check for no data exists" );
\r
1445 div.data("test", "success");
\r
1446 equals( div.data("test"), "success", "Check for added data" );
\r
1447 div.data("test", "overwritten");
\r
1448 equals( div.data("test"), "overwritten", "Check for overwritten data" );
\r
1449 div.data("test", undefined);
\r
1450 equals( div.data("test"), "overwritten", "Check that data wasn't removed");
\r
1451 div.data("test", null);
\r
1452 ok( div.data("test") === null, "Check for null data");
\r
1454 div.data("test", "overwritten");
\r
1455 var hits = {test:0}, gets = {test:0};
\r
1458 .bind("setData",function(e,key,value){ hits[key] += value; })
\r
1459 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
\r
1460 .bind("getData",function(e,key){ gets[key] += 1; })
\r
1461 .bind("getData.foo",function(e,key){ gets[key] += 3; });
\r
1463 div.data("test.foo", 2);
\r
1464 equals( div.data("test"), "overwritten", "Check for original data" );
\r
1465 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
1466 equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
\r
1467 equals( hits.test, 2, "Check triggered setter functions" );
\r
1468 equals( gets.test, 5, "Check triggered getter functions" );
\r
1473 div.data("test", 1);
\r
1474 equals( div.data("test"), 1, "Check for original data" );
\r
1475 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
1476 equals( div.data("test.bar"), 1, "Check for unmatched namespace" );
\r
1477 equals( hits.test, 1, "Check triggered setter functions" );
\r
1478 equals( gets.test, 5, "Check triggered getter functions" );
\r
1484 .bind("getData",function(e,key){ return key + "root"; })
\r
1485 .bind("getData.foo",function(e,key){ return key + "foo"; });
\r
1487 equals( div.data("test"), "testroot", "Check for original data" );
\r
1488 equals( div.data("test.foo"), "testfoo", "Check for namespaced data" );
\r
1489 equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
\r
1492 test("$.removeData", function() {
\r
1494 var div = $("#foo")[0];
\r
1495 jQuery.data(div, "test", "testing");
\r
1496 jQuery.removeData(div, "test");
\r
1497 equals( jQuery.data(div, "test"), undefined, "Check removal of data" );
\r
1500 test(".removeData()", function() {
\r
1502 var div = $("#foo");
\r
1503 div.data("test", "testing");
\r
1504 div.removeData("test");
\r
1505 equals( div.data("test"), undefined, "Check removal of data" );
\r
1507 div.data("test", "testing");
\r
1508 div.data("test.foo", "testing2");
\r
1509 div.removeData("test.bar");
\r
1510 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
1511 equals( div.data("test"), "testing", "Make sure data is intact" );
\r
1513 div.removeData("test");
\r
1514 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
1515 equals( div.data("test"), undefined, "Make sure data is intact" );
\r
1517 div.removeData("test.foo");
\r
1518 equals( div.data("test.foo"), undefined, "Make sure data is intact" );
\r
1521 test("remove()", function() {
\r
1523 $("#ap").children().remove();
\r
1524 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
1525 equals( $("#ap").children().length, 0, "Check remove" );
\r
1528 $("#ap").children().remove("a");
\r
1529 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
1530 equals( $("#ap").children().length, 1, "Check filtered remove" );
\r
1532 // using contents will get comments regular, text, and comment nodes
\r
1533 equals( $("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
\r
1534 $("#nonnodes").contents().remove();
\r
1535 equals( $("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
\r
1538 test("empty()", function() {
\r
1540 equals( $("#ap").children().empty().text().length, 0, "Check text is removed" );
\r
1541 equals( $("#ap").children().length, 4, "Check elements are not removed" );
\r
1543 // using contents will get comments regular, text, and comment nodes
\r
1544 var j = $("#nonnodes").contents();
\r
1546 equals( j.html(), "", "Check node,textnode,comment empty works" );
\r
1549 test("slice()", function() {
\r
1551 isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
\r
1552 isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
\r
1553 isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
\r
1554 isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
\r
1556 isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
\r
1559 test("map()", function() {
\r
1560 expect(2);//expect(6);
\r
1563 $("#ap").map(function(){
\r
1564 return $(this).find("a").get();
\r
1566 q("google", "groups", "anchor1", "mark"),
\r
1571 $("#ap > a").map(function(){
\r
1572 return this.parentNode;
\r
1574 q("ap","ap","ap"),
\r
1578 return;//these haven't been accepted yet
\r
1581 var keys = $.map( {a:1,b:2}, function( v, k ){
\r
1585 equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
\r
1587 var values = $.map( {a:1,b:2}, function( v, k ){
\r
1591 equals( values.join(""), "12", "Map the values from a hash to an array" );
\r
1593 var scripts = document.getElementsByTagName("script");
\r
1594 var mapped = $.map( scripts, function( v, k ){
\r
1598 equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
\r
1600 var flat = $.map( Array(4), function( v, k ){
\r
1601 return k % 2 ? k : [k,k,k];//try mixing array and regular returns
\r
1604 equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
\r
1607 test("contents()", function() {
\r
1609 equals( $("#ap").contents().length, 9, "Check element contents" );
\r
1610 ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
\r
1611 var ibody = $("#loadediframe").contents()[0].body;
\r
1612 ok( ibody, "Check existance of IFrame body" );
\r
1614 equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
\r
1616 $(ibody).append("<div>init text</div>");
\r
1617 equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
\r
1619 equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
\r
1621 $("div:last", ibody).text("div text");
\r
1622 equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
\r
1624 $("div:last", ibody).remove();
\r
1625 equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
\r
1627 equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
\r
1629 $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
\r
1630 $("table", ibody).remove();
\r
1631 equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
\r
1633 // using contents will get comments regular, text, and comment nodes
\r
1634 var c = $("#nonnodes").contents().contents();
\r
1635 equals( c.length, 1, "Check node,textnode,comment contents is just one" );
\r
1636 equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
\r
1639 test("$.makeArray", function(){
\r
1642 equals( $.makeArray($('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" );
\r
1644 equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
\r
1646 equals( (function(){ return $.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
\r
1648 equals( $.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
\r
1650 equals( $.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
\r
1652 equals( $.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
\r
1654 equals( $.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
\r
1656 equals( $.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
\r
1658 equals( $.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
\r
1660 equals( $.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
\r
1662 equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodes array" );
\r
1664 //function, is tricky as it has length
\r
1665 equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
\r
1666 //window, also has length
\r
1667 equals( $.makeArray(window)[0], window, "Pass makeArray the window" );
\r
1669 equals( $.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
\r
1671 ok( $.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
\r