Fixed line-ending issue.
[jquery.git] / test / unit / core.js
1 module("core");
2
3 test("Basic requirements", function() {
4         expect(7);
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" );
11         ok( $, "$" );
12 });
13
14 test("jQuery()", function() {
15         expect(8);
16
17         var main = jQuery("#main");
18         isSet( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
19
20 /*
21         // disabled since this test was doing nothing. i tried to fix it but i'm not sure
22         // what the expected behavior should even be. FF returns "\n" for the text node
23         // make sure this is handled
24         var crlfContainer = jQuery('<p>\r\n</p>');
25         var x = crlfContainer.contents().get(0).nodeValue;
26         equals( x, what???, "Check for \\r and \\n in jQuery()" );
27 */
28
29         /* // Disabled until we add this functionality in
30         var pass = true;
31         try {
32                 jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
33         } catch(e){
34                 pass = false;
35         }
36         ok( pass, "jQuery('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
37
38         var code = jQuery("<code/>");
39         equals( code.length, 1, "Correct number of elements generated for code" );
40         var img = jQuery("<img/>");
41         equals( img.length, 1, "Correct number of elements generated for img" );
42         var div = jQuery("<div/><hr/><code/><b/>");
43         equals( div.length, 4, "Correct number of elements generated for div hr code b" );
44
45         // can actually yield more than one, when iframes are included, the window is an array as well
46         equals( jQuery(window).length, 1, "Correct number of elements generated for window" );
47
48         equals( jQuery(document).length, 1, "Correct number of elements generated for document" );
49
50         equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
51
52         equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" );
53 });
54
55 test("selector state", function() {
56         expect(26);
57
58         var test;
59         
60         test = jQuery();
61         equals( test.selector, "", "Empty jQuery Selector" );
62         equals( test.context, document, "Empty jQuery Context" );
63         
64         test = jQuery(document);
65         equals( test.selector, "", "Document Selector" );
66         equals( test.context, document, "Document Context" );
67         
68         test = jQuery(document.body);
69         equals( test.selector, "", "Body Selector" );
70         equals( test.context, document.body, "Body Context" );
71         
72         test = jQuery("#main");
73         equals( test.selector, "#main", "#main Selector" );
74         equals( test.context, document, "#main Context" );
75         
76         test = jQuery("#main", document);
77         equals( test.selector, "#main", "#main Selector" );
78         equals( test.context, document, "#main Context" );
79         
80         test = jQuery("#main", document.body);
81         equals( test.selector, "#main", "#main Selector" );
82         equals( test.context, document.body, "#main Context" );
83         
84         test = jQuery(document.body).find("#main");
85         equals( test.selector, "#main", "#main find Selector" );
86         equals( test.context, document.body, "#main find Context" );
87
88         test = jQuery("#main").filter("div");
89         equals( test.selector, "#main.filter(div)", "#main filter Selector" );
90         equals( test.context, document, "#main filter Context" );
91         
92         test = jQuery("#main").not("div");
93         equals( test.selector, "#main.not(div)", "#main not Selector" );
94         equals( test.context, document, "#main not Context" );
95         
96         test = jQuery("#main").filter("div").not("div");
97         equals( test.selector, "#main.filter(div).not(div)", "#main filter, not Selector" );
98         equals( test.context, document, "#main filter, not Context" );
99         
100         test = jQuery("#main").filter("div").not("div").end();
101         equals( test.selector, "#main.filter(div)", "#main filter, not, end Selector" );
102         equals( test.context, document, "#main filter, not, end Context" );
103         
104         test = jQuery("#main").parent("body");
105         equals( test.selector, "#main.parent(body)", "#main parent Selector" );
106         equals( test.context, document, "#main parent Context" );
107         
108         test = jQuery("#main").eq(0);
109         equals( test.selector, "#main.slice(0,1)", "#main eq Selector" );
110         equals( test.context, document, "#main eq Context" );
111 });
112
113 test("browser", function() {
114         expect(13);
115         var browsers = {
116                 //Internet Explorer
117                 "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0",
118                 "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",
119                 /** Failing #1876
120                  * "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",
121                  */
122                 //Browsers with Gecko engine
123                 //Mozilla
124                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12",
125                 //Firefox
126                 "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",
127                 //Netscape
128                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5",
129                 //Flock
130                 "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",
131                 //Opera browser
132                 "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
133                 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
134                 "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20",
135                 //WebKit engine
136                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
137                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
138                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
139                 //Other user agent string
140                 "Other browser's user agent 1.0":null
141         };
142         for (var i in browsers) {
143                 var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
144                 version = v ? v[1] : null;
145                 equals( version, browsers[i], "Checking UA string" );
146         }
147 });
148
149 test("noConflict", function() {
150         expect(6);
151
152         var $$ = jQuery;
153
154         equals( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
155         equals( jQuery, $$, "Make sure jQuery wasn't touched." );
156         equals( $, original$, "Make sure $ was reverted." );
157
158         jQuery = $ = $$;
159
160         equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
161         equals( jQuery, originaljQuery, "Make sure jQuery was reverted." );
162         equals( $, original$, "Make sure $ was reverted." );
163
164         jQuery = $$;
165 });
166
167 test("isFunction", function() {
168         expect(19);
169
170         // Make sure that false values return false
171         ok( !jQuery.isFunction(), "No Value" );
172         ok( !jQuery.isFunction( null ), "null Value" );
173         ok( !jQuery.isFunction( undefined ), "undefined Value" );
174         ok( !jQuery.isFunction( "" ), "Empty String Value" );
175         ok( !jQuery.isFunction( 0 ), "0 Value" );
176
177         // Check built-ins
178         // Safari uses "(Internal Function)"
179         ok( jQuery.isFunction(String), "String Function("+String+")" );
180         ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
181         ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
182         ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
183
184         // When stringified, this could be misinterpreted
185         var mystr = "function";
186         ok( !jQuery.isFunction(mystr), "Function String" );
187
188         // When stringified, this could be misinterpreted
189         var myarr = [ "function" ];
190         ok( !jQuery.isFunction(myarr), "Function Array" );
191
192         // When stringified, this could be misinterpreted
193         var myfunction = { "function": "test" };
194         ok( !jQuery.isFunction(myfunction), "Function Object" );
195
196         // Make sure normal functions still work
197         var fn = function(){};
198         ok( jQuery.isFunction(fn), "Normal Function" );
199
200         var obj = document.createElement("object");
201
202         // Firefox says this is a function
203         ok( !jQuery.isFunction(obj), "Object Element" );
204
205         // IE says this is an object
206         // Since 1.3, this isn't supported (#2968)
207         //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
208
209         var nodes = document.body.childNodes;
210
211         // Safari says this is a function
212         ok( !jQuery.isFunction(nodes), "childNodes Property" );
213
214         var first = document.body.firstChild;
215
216         // Normal elements are reported ok everywhere
217         ok( !jQuery.isFunction(first), "A normal DOM Element" );
218
219         var input = document.createElement("input");
220         input.type = "text";
221         document.body.appendChild( input );
222
223         // IE says this is an object
224         // Since 1.3, this isn't supported (#2968)
225         //ok( jQuery.isFunction(input.focus), "A default function property" );
226
227         document.body.removeChild( input );
228
229         var a = document.createElement("a");
230         a.href = "some-function";
231         document.body.appendChild( a );
232
233         // This serializes with the word 'function' in it
234         ok( !jQuery.isFunction(a), "Anchor Element" );
235
236         document.body.removeChild( a );
237
238         // Recursive function calls have lengths and array-like properties
239         function callme(callback){
240                 function fn(response){
241                         callback(response);
242                 }
243
244                 ok( jQuery.isFunction(fn), "Recursive Function Call" );
245
246                 fn({ some: "data" });
247         };
248
249         callme(function(){
250                 callme(function(){});
251         });
252 });
253
254 var foo = false;
255
256 test("jQuery('html')", function() {
257         expect(6);
258
259         reset();
260         foo = false;
261         var s = jQuery("<script>foo='test';</script>")[0];
262         ok( s, "Creating a script" );
263         ok( !foo, "Make sure the script wasn't executed prematurely" );
264         jQuery("body").append("<script>foo='test';</script>");
265         ok( foo, "Executing a scripts contents in the right context" );
266
267         reset();
268         ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
269
270         reset();
271
272         var j = jQuery("<span>hi</span> there <!-- mon ami -->");
273         ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
274
275         ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
276 });
277
278 test("jQuery('html', context)", function() {
279         expect(1);
280
281         var $div = jQuery("<div/>");
282         var $span = jQuery("<span/>", $div);
283         equals($span.length, 1, "Verify a span created with a div context works, #1763");
284 });
285
286 if ( !isLocal ) {
287 test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
288         expect(2);
289         stop();
290         jQuery.get('data/dashboard.xml', function(xml) {
291                 // tests for #1419 where IE was a problem
292                 equals( jQuery("tab:first", xml).text(), "blabla", "Verify initial text correct" );
293                 jQuery("tab:first", xml).text("newtext");
294                 equals( jQuery("tab:first", xml).text(), "newtext", "Verify new text correct" );
295                 start();
296         });
297 });
298 }
299
300 test("length", function() {
301         expect(1);
302         equals( jQuery("p").length, 6, "Get Number of Elements Found" );
303 });
304
305 test("size()", function() {
306         expect(1);
307         equals( jQuery("p").size(), 6, "Get Number of Elements Found" );
308 });
309
310 test("get()", function() {
311         expect(1);
312         isSet( jQuery("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
313 });
314
315 test("get(Number)", function() {
316         expect(1);
317         equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
318 });
319
320 test("add(String|Element|Array|undefined)", function() {
321         expect(12);
322         isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
323         isSet( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
324         ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
325
326         // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
327         // use jQuery([]).add(form.elements) instead.
328         //equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
329
330         var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
331         equals( x[0].id, "x1", "Check on-the-fly element1" );
332         equals( x[1].id, "x2", "Check on-the-fly element2" );
333
334         var x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
335         equals( x[0].id, "x1", "Check on-the-fly element1" );
336         equals( x[1].id, "x2", "Check on-the-fly element2" );
337
338         var notDefined;
339         equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
340
341         // Added after #2811
342         equals( jQuery([]).add([window,document,document.body,document]).length, 3, "Pass an array" );
343         equals( jQuery(document).add(document).length, 1, "Check duplicated elements" );
344         equals( jQuery(window).add(window).length, 1, "Check duplicated elements using the window" );
345         ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
346 });
347
348 test("each(Function)", function() {
349         expect(1);
350         var div = jQuery("div");
351         div.each(function(){this.foo = 'zoo';});
352         var pass = true;
353         for ( var i = 0; i < div.size(); i++ ) {
354                 if ( div.get(i).foo != "zoo" ) pass = false;
355         }
356         ok( pass, "Execute a function, Relative" );
357 });
358
359 test("index(Object)", function() {
360         expect(10);
361
362         var elements = jQuery([window, document]),
363                 inputElements = jQuery('#radio1,#radio2,#check1,#check2');
364
365         equals( elements.index(window), 0, "Check for index of elements" );
366         equals( elements.index(document), 1, "Check for index of elements" );
367         equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" );
368         equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" );
369         equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" );
370         equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" );
371         equals( inputElements.index(window), -1, "Check for not found index" );
372         equals( inputElements.index(document), -1, "Check for not found index" );
373
374         // enabled since [5500]
375         equals( elements.index( elements ), 0, "Pass in a jQuery object" );
376         equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
377 });
378
379 test("attr(String)", function() {
380         expect(26);
381         equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
382         equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
383         equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
384         equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
385         equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' );
386         equals( jQuery('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' );
387         equals( jQuery('#google').attr('title'), "Google!", 'Check for title attribute' );
388         equals( jQuery('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' );
389         equals( jQuery('#en').attr('lang'), "en", 'Check for lang attribute' );
390         equals( jQuery('#simon').attr('class'), "blog link", 'Check for class attribute' );
391         equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' );
392         equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' );
393         ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
394         equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
395         equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
396         equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
397         equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' );
398         equals( jQuery('#foo').attr('nodeName'), 'DIV', 'Check for nodeName attribute' );
399         equals( jQuery('#foo').attr('tagName'), 'DIV', 'Check for tagName attribute' );
400
401         jQuery('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
402         equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );
403
404
405         // Related to [5574] and [5683]
406         var body = document.body, $body = jQuery(body);
407
408         ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' );
409         ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' );
410         
411         body.setAttribute('foo', 'baz');
412         equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' );
413         
414         body.foo = 'bar';
415         equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' );
416         
417         $body.attr('foo','cool');
418         equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' );
419         
420         body.foo = undefined;
421         ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
422         
423         body.removeAttribute('foo'); // Cleanup
424 });
425
426 if ( !isLocal ) {
427         test("attr(String) in XML Files", function() {
428                 expect(2);
429                 stop();
430                 jQuery.get("data/dashboard.xml", function(xml) {
431                         equals( jQuery("locations", xml).attr("class"), "foo", "Check class attribute in XML document" );
432                         equals( jQuery("location", xml).attr("for"), "bar", "Check for attribute in XML document" );
433                         start();
434                 });
435         });
436 }
437
438 test("attr(String, Function)", function() {
439         expect(2);
440         equals( jQuery('#text1').attr('value', function() { return this.id })[0].value, "text1", "Set value from id" );
441         equals( jQuery('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index");
442 });
443
444 test("attr(Hash)", function() {
445         expect(1);
446         var pass = true;
447         jQuery("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
448                 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
449         });
450         ok( pass, "Set Multiple Attributes" );
451 });
452
453 test("attr(String, Object)", function() {
454         expect(17);
455         var div = jQuery("div").attr("foo", "bar");
456                 fail = false;
457         for ( var i = 0; i < div.size(); i++ ) {
458                 if ( div.get(i).getAttribute('foo') != "bar" ){
459                         fail = i;
460                         break;
461                 }
462         }
463         equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
464
465         ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
466
467         jQuery("#name").attr('name', 'something');
468         equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' );
469         jQuery("#check2").attr('checked', true);
470         equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
471         jQuery("#check2").attr('checked', false);
472         equals( document.getElementById('check2').checked, false, 'Set checked attribute' );
473         jQuery("#text1").attr('readonly', true);
474         equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' );
475         jQuery("#text1").attr('readonly', false);
476         equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' );
477         jQuery("#name").attr('maxlength', '5');
478         equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' );
479         jQuery("#name").attr('maxLength', '10');
480         equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
481
482         // for #1070
483         jQuery("#name").attr('someAttr', '0');
484         equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
485         jQuery("#name").attr('someAttr', 0);
486         equals( jQuery("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
487         jQuery("#name").attr('someAttr', 1);
488         equals( jQuery("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
489
490         // using contents will get comments regular, text, and comment nodes
491         var j = jQuery("#nonnodes").contents();
492
493         j.attr("name", "attrvalue");
494         equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
495         j.removeAttr("name");
496
497         reset();
498
499         var type = jQuery("#check2").attr('type');
500         var thrown = false;
501         try {
502                 jQuery("#check2").attr('type','hidden');
503         } catch(e) {
504                 thrown = true;
505         }
506         ok( thrown, "Exception thrown when trying to change type property" );
507         equals( type, jQuery("#check2").attr('type'), "Verify that you can't change the type of an input element" );
508
509         var check = document.createElement("input");
510         var thrown = true;
511         try {
512                 jQuery(check).attr('type','checkbox');
513         } catch(e) {
514                 thrown = false;
515         }
516         ok( thrown, "Exception thrown when trying to change type property" );
517         equals( "checkbox", jQuery(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
518 });
519
520 if ( !isLocal ) {
521         test("attr(String, Object) - Loaded via XML document", function() {
522                 expect(2);
523                 stop();
524                 jQuery.get('data/dashboard.xml', function(xml) {
525                         var titles = [];
526                         jQuery('tab', xml).each(function() {
527                                 titles.push(jQuery(this).attr('title'));
528                         });
529                         equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
530                         equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
531                         start();
532                 });
533         });
534 }
535
536 test("css(String|Hash)", function() {
537         expect(19);
538
539         equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
540
541         ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
542         jQuery('#foo').css({display: 'none'});
543         ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
544         jQuery('#foo').css({display: 'block'});
545         ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
546
547         jQuery('#floatTest').css({styleFloat: 'right'});
548         equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
549         jQuery('#floatTest').css({cssFloat: 'left'});
550         equals( jQuery('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
551         jQuery('#floatTest').css({'float': 'right'});
552         equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
553         jQuery('#floatTest').css({'font-size': '30px'});
554         equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
555
556         jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
557                 jQuery('#foo').css({opacity: n});
558                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
559                 jQuery('#foo').css({opacity: parseFloat(n)});
560                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
561         });
562         jQuery('#foo').css({opacity: ''});
563         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
564 });
565
566 test("css(String, Object)", function() {
567         expect(21);
568         ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
569         jQuery('#foo').css('display', 'none');
570         ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
571         jQuery('#foo').css('display', 'block');
572         ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
573
574         jQuery('#floatTest').css('styleFloat', 'left');
575         equals( jQuery('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
576         jQuery('#floatTest').css('cssFloat', 'right');
577         equals( jQuery('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
578         jQuery('#floatTest').css('float', 'left');
579         equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
580         jQuery('#floatTest').css('font-size', '20px');
581         equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
582
583         jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
584                 jQuery('#foo').css('opacity', n);
585                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
586                 jQuery('#foo').css('opacity', parseFloat(n));
587                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
588         });
589         jQuery('#foo').css('opacity', '');
590         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
591         // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
592         if (jQuery.browser.msie) {
593                 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
594         }
595         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
596
597         // using contents will get comments regular, text, and comment nodes
598         var j = jQuery("#nonnodes").contents();
599         j.css("padding-left", "1px");
600         equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
601
602         // opera sometimes doesn't update 'display' correctly, see #2037
603         jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
604         equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
605 });
606
607 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
608         expect(4);
609
610         var $checkedtest = jQuery("#checkedtest");
611         // IE6 was clearing "checked" in jQuery.css(elem, "height");
612         jQuery.css($checkedtest[0], "height");
613         ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
614         ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
615         ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
616         ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
617 });
618
619 test("width()", function() {
620         expect(9);
621
622         var $div = jQuery("#nothiddendiv");
623         $div.width(30);
624         equals($div.width(), 30, "Test set to 30 correctly");
625         $div.width(-1); // handle negative numbers by ignoring #1599
626         equals($div.width(), 30, "Test negative width ignored");
627         $div.css("padding", "20px");
628         equals($div.width(), 30, "Test padding specified with pixels");
629         $div.css("border", "2px solid #fff");
630         equals($div.width(), 30, "Test border specified with pixels");
631         $div.css("padding", "2em");
632         equals($div.width(), 30, "Test padding specified with ems");
633         $div.css("border", "1em solid #fff");
634         equals($div.width(), 30, "Test border specified with ems");
635         $div.css("padding", "2%");
636         equals($div.width(), 30, "Test padding specified with percent");
637         $div.hide();
638         equals($div.width(), 30, "Test hidden div");
639
640         $div.css({ display: "", border: "", padding: "" });
641
642         jQuery("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
643         equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
644         jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
645 });
646
647 test("height()", function() {
648         expect(8);
649
650         var $div = jQuery("#nothiddendiv");
651         $div.height(30);
652         equals($div.height(), 30, "Test set to 30 correctly");
653         $div.height(-1); // handle negative numbers by ignoring #1599
654         equals($div.height(), 30, "Test negative height ignored");
655         $div.css("padding", "20px");
656         equals($div.height(), 30, "Test padding specified with pixels");
657         $div.css("border", "2px solid #fff");
658         equals($div.height(), 30, "Test border specified with pixels");
659         $div.css("padding", "2em");
660         equals($div.height(), 30, "Test padding specified with ems");
661         $div.css("border", "1em solid #fff");
662         equals($div.height(), 30, "Test border specified with ems");
663         $div.css("padding", "2%");
664         equals($div.height(), 30, "Test padding specified with percent");
665         $div.hide();
666         equals($div.height(), 30, "Test hidden div");
667
668         $div.css({ display: "", border: "", padding: "", height: "1px" });
669 });
670
671 test("text()", function() {
672         expect(1);
673         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
674         equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
675 });
676
677 test("wrap(String|Element)", function() {
678         expect(8);
679         var defaultText = 'Try them out:'
680         var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
681         equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
682         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
683
684         reset();
685         var defaultText = 'Try them out:'
686         var result = jQuery('#first').wrap(document.getElementById('empty')).parent();
687         ok( result.is('ol'), 'Check for element wrapping' );
688         equals( result.text(), defaultText, 'Check for element wrapping' );
689
690         reset();
691         jQuery('#check1').click(function() {
692                 var checkbox = this;
693                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
694                 jQuery(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
695                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
696         }).click();
697
698         // using contents will get comments regular, text, and comment nodes
699         var j = jQuery("#nonnodes").contents();
700         j.wrap("<i></i>");
701         equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
702         equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
703 });
704
705 test("wrapAll(String|Element)", function() {
706         expect(8);
707         var prev = jQuery("#first")[0].previousSibling;
708         var p = jQuery("#first")[0].parentNode;
709         var result = jQuery('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
710         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
711         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
712         ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
713         equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
714         equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
715
716         reset();
717         var prev = jQuery("#first")[0].previousSibling;
718         var p = jQuery("#first")[0].parentNode;
719         var result = jQuery('#first,#firstp').wrapAll(document.getElementById('empty'));
720         equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
721         equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
722         equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
723 });
724
725 test("wrapInner(String|Element)", function() {
726         expect(6);
727         var num = jQuery("#first").children().length;
728         var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
729         equals( jQuery("#first").children().length, 1, "Only one child" );
730         ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
731         equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
732
733         reset();
734         var num = jQuery("#first").children().length;
735         var result = jQuery('#first').wrapInner(document.getElementById('empty'));
736         equals( jQuery("#first").children().length, 1, "Only one child" );
737         ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
738         equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
739 });
740
741 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
742         expect(21);
743         var defaultText = 'Try them out:'
744         var result = jQuery('#first').append('<b>buga</b>');
745         equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
746         equals( jQuery('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
747
748         reset();
749         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
750         jQuery('#sap').append(document.getElementById('first'));
751         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
752
753         reset();
754         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
755         jQuery('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
756         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
757
758         reset();
759         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
760         jQuery('#sap').append(jQuery("#first, #yahoo"));
761         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
762
763         reset();
764         jQuery("#sap").append( 5 );
765         ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
766
767         reset();
768         jQuery("#sap").append( " text with spaces " );
769         ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
770
771         reset();
772         ok( jQuery("#sap").append([]), "Check for appending an empty array." );
773         ok( jQuery("#sap").append(""), "Check for appending an empty string." );
774         ok( jQuery("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
775
776         reset();
777         jQuery("#sap").append(document.getElementById('form'));
778         equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
779
780         reset();
781         var pass = true;
782         try {
783                 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
784         } catch(e) {
785                 pass = false;
786         }
787
788         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
789
790         reset();
791         jQuery('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
792         t( 'Append legend', '#legend', ['legend'] );
793
794         reset();
795         jQuery('#select1').append('<OPTION>Test</OPTION>');
796         equals( jQuery('#select1 option:last').text(), "Test", "Appending &lt;OPTION&gt; (all caps)" );
797
798         jQuery('#table').append('<colgroup></colgroup>');
799         ok( jQuery('#table colgroup').length, "Append colgroup" );
800
801         jQuery('#table colgroup').append('<col/>');
802         ok( jQuery('#table colgroup col').length, "Append col" );
803
804         reset();
805         jQuery('#table').append('<caption></caption>');
806         ok( jQuery('#table caption').length, "Append caption" );
807
808         reset();
809         jQuery('form:last')
810                 .append('<select id="appendSelect1"></select>')
811                 .append('<select id="appendSelect2"><option>Test</option></select>');
812
813         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
814
815         // using contents will get comments regular, text, and comment nodes
816         var j = jQuery("#nonnodes").contents();
817         var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
818         equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
819         ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
820         d.contents().appendTo("#nonnodes");
821         d.remove();
822         ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
823 });
824
825 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
826         expect(6);
827         var defaultText = 'Try them out:'
828         jQuery('<b>buga</b>').appendTo('#first');
829         equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
830         equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
831
832         reset();
833         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
834         jQuery(document.getElementById('first')).appendTo('#sap');
835         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
836
837         reset();
838         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
839         jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
840         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
841
842         reset();
843         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
844         jQuery("#first, #yahoo").appendTo('#sap');
845         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
846
847         reset();
848         jQuery('#select1').appendTo('#foo');
849         t( 'Append select', '#foo select', ['select1'] );
850 });
851
852 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
853         expect(5);
854         var defaultText = 'Try them out:'
855         var result = jQuery('#first').prepend('<b>buga</b>');
856         equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
857         equals( jQuery('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
858
859         reset();
860         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
861         jQuery('#sap').prepend(document.getElementById('first'));
862         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
863
864         reset();
865         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
866         jQuery('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
867         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
868
869         reset();
870         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
871         jQuery('#sap').prepend(jQuery("#first, #yahoo"));
872         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
873 });
874
875 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
876         expect(6);
877         var defaultText = 'Try them out:'
878         jQuery('<b>buga</b>').prependTo('#first');
879         equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
880         equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
881
882         reset();
883         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
884         jQuery(document.getElementById('first')).prependTo('#sap');
885         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
886
887         reset();
888         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
889         jQuery([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
890         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
891
892         reset();
893         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
894         jQuery("#yahoo, #first").prependTo('#sap');
895         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
896
897         reset();
898         jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
899         jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
900
901         t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
902 });
903
904 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
905         expect(4);
906         var expected = 'This is a normal link: bugaYahoo';
907         jQuery('#yahoo').before('<b>buga</b>');
908         equals( expected, jQuery('#en').text(), 'Insert String before' );
909
910         reset();
911         expected = "This is a normal link: Try them out:Yahoo";
912         jQuery('#yahoo').before(document.getElementById('first'));
913         equals( expected, jQuery('#en').text(), "Insert element before" );
914
915         reset();
916         expected = "This is a normal link: Try them out:diveintomarkYahoo";
917         jQuery('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
918         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
919
920         reset();
921         expected = "This is a normal link: Try them out:diveintomarkYahoo";
922         jQuery('#yahoo').before(jQuery("#first, #mark"));
923         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
924 });
925
926 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
927         expect(4);
928         var expected = 'This is a normal link: bugaYahoo';
929         jQuery('<b>buga</b>').insertBefore('#yahoo');
930         equals( expected, jQuery('#en').text(), 'Insert String before' );
931
932         reset();
933         expected = "This is a normal link: Try them out:Yahoo";
934         jQuery(document.getElementById('first')).insertBefore('#yahoo');
935         equals( expected, jQuery('#en').text(), "Insert element before" );
936
937         reset();
938         expected = "This is a normal link: Try them out:diveintomarkYahoo";
939         jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
940         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
941
942         reset();
943         expected = "This is a normal link: Try them out:diveintomarkYahoo";
944         jQuery("#first, #mark").insertBefore('#yahoo');
945         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
946 });
947
948 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
949         expect(4);
950         var expected = 'This is a normal link: Yahoobuga';
951         jQuery('#yahoo').after('<b>buga</b>');
952         equals( expected, jQuery('#en').text(), 'Insert String after' );
953
954         reset();
955         expected = "This is a normal link: YahooTry them out:";
956         jQuery('#yahoo').after(document.getElementById('first'));
957         equals( expected, jQuery('#en').text(), "Insert element after" );
958
959         reset();
960         expected = "This is a normal link: YahooTry them out:diveintomark";
961         jQuery('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
962         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
963
964         reset();
965         expected = "This is a normal link: YahooTry them out:diveintomark";
966         jQuery('#yahoo').after(jQuery("#first, #mark"));
967         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
968 });
969
970 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
971         expect(4);
972         var expected = 'This is a normal link: Yahoobuga';
973         jQuery('<b>buga</b>').insertAfter('#yahoo');
974         equals( expected, jQuery('#en').text(), 'Insert String after' );
975
976         reset();
977         expected = "This is a normal link: YahooTry them out:";
978         jQuery(document.getElementById('first')).insertAfter('#yahoo');
979         equals( expected, jQuery('#en').text(), "Insert element after" );
980
981         reset();
982         expected = "This is a normal link: YahooTry them out:diveintomark";
983         jQuery([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
984         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
985
986         reset();
987         expected = "This is a normal link: YahooTry them out:diveintomark";
988         jQuery("#mark, #first").insertAfter('#yahoo');
989         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
990 });
991
992 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
993         expect(10);
994         jQuery('#yahoo').replaceWith('<b id="replace">buga</b>');
995         ok( jQuery("#replace")[0], 'Replace element with string' );
996         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
997
998         reset();
999         jQuery('#yahoo').replaceWith(document.getElementById('first'));
1000         ok( jQuery("#first")[0], 'Replace element with element' );
1001         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
1002
1003         reset();
1004         jQuery('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
1005         ok( jQuery("#first")[0], 'Replace element with array of elements' );
1006         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
1007         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
1008
1009         reset();
1010         jQuery('#yahoo').replaceWith(jQuery("#first, #mark"));
1011         ok( jQuery("#first")[0], 'Replace element with set of elements' );
1012         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
1013         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
1014 });
1015
1016 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
1017         expect(10);
1018         jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
1019         ok( jQuery("#replace")[0], 'Replace element with string' );
1020         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
1021
1022         reset();
1023         jQuery(document.getElementById('first')).replaceAll("#yahoo");
1024         ok( jQuery("#first")[0], 'Replace element with element' );
1025         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
1026
1027         reset();
1028         jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
1029         ok( jQuery("#first")[0], 'Replace element with array of elements' );
1030         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
1031         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
1032
1033         reset();
1034         jQuery("#first, #mark").replaceAll("#yahoo");
1035         ok( jQuery("#first")[0], 'Replace element with set of elements' );
1036         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
1037         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
1038 });
1039
1040 test("end()", function() {
1041         expect(3);
1042         equals( 'Yahoo', jQuery('#yahoo').parent().end().text(), 'Check for end' );
1043         ok( jQuery('#yahoo').end(), 'Check for end with nothing to end' );
1044
1045         var x = jQuery('#yahoo');
1046         x.parent();
1047         equals( 'Yahoo', jQuery('#yahoo').text(), 'Check for non-destructive behaviour' );
1048 });
1049
1050 test("find(String)", function() {
1051         expect(2);
1052         equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
1053
1054         // using contents will get comments regular, text, and comment nodes
1055         var j = jQuery("#nonnodes").contents();
1056         equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
1057 });
1058
1059 test("clone()", function() {
1060         expect(20);
1061         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
1062         var clone = jQuery('#yahoo').clone();
1063         equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
1064         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
1065
1066         var cloneTags = [
1067                 "<table/>", "<tr/>", "<td/>", "<div/>",
1068                 "<button/>", "<ul/>", "<ol/>", "<li/>",
1069                 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
1070                 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
1071         ];
1072         for (var i = 0; i < cloneTags.length; i++) {
1073                 var j = jQuery(cloneTags[i]);
1074                 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1));
1075         }
1076
1077         // using contents will get comments regular, text, and comment nodes
1078         var cl = jQuery("#nonnodes").contents().clone();
1079         ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
1080 });
1081
1082 if (!isLocal) {
1083 test("clone() on XML nodes", function() {
1084         expect(2);
1085         stop();
1086         jQuery.get("data/dashboard.xml", function (xml) {
1087                 var root = jQuery(xml.documentElement).clone();
1088                 jQuery("tab:first", xml).text("origval");
1089                 jQuery("tab:first", root).text("cloneval");
1090                 equals(jQuery("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
1091                 equals(jQuery("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
1092                 start();
1093         });
1094 });
1095 }
1096
1097 test("is(String)", function() {
1098         expect(26);
1099         ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' );
1100         ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' );
1101         ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1102         ok( !jQuery('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1103         ok( jQuery('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1104         ok( !jQuery('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1105         ok( jQuery('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1106         ok( !jQuery('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1107         ok( jQuery('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1108         ok( !jQuery('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1109         ok( jQuery('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1110         ok( !jQuery('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1111         ok( jQuery('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1112         ok( !jQuery('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1113         ok( jQuery('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
1114         ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
1115         ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1116         ok( !jQuery('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1117         ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' );
1118         ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' );
1119         ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' );
1120         ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1121
1122         // test is() with comma-seperated expressions
1123         ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1124         ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1125         ok( jQuery('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1126         ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1127 });
1128
1129 test("jQuery.extend(Object, Object)", function() {
1130         expect(20);
1131
1132         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1133                 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1134                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1135                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
1136                 deep1 = { foo: { bar: true } },
1137                 deep1copy = { foo: { bar: true } },
1138                 deep2 = { foo: { baz: true }, foo2: document },
1139                 deep2copy = { foo: { baz: true }, foo2: document },
1140                 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
1141
1142         jQuery.extend(settings, options);
1143         isObj( settings, merged, "Check if extended: settings must be extended" );
1144         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1145
1146         jQuery.extend(settings, null, options);
1147         isObj( settings, merged, "Check if extended: settings must be extended" );
1148         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1149
1150         jQuery.extend(true, deep1, deep2);
1151         isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
1152         isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
1153         equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
1154
1155         var nullUndef;
1156         nullUndef = jQuery.extend({}, options, { xnumber2: null });
1157         ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
1158
1159         nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
1160         ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
1161
1162         nullUndef = jQuery.extend({}, options, { xnumber0: null });
1163         ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
1164
1165         var target = {};
1166         var recursive = { foo:target, bar:5 };
1167         jQuery.extend(true, target, recursive);
1168         isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
1169
1170         var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
1171         equals( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
1172
1173         var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
1174         ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
1175
1176         var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
1177         ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
1178
1179         var obj = { foo:null };
1180         jQuery.extend(true, obj, { foo:"notnull" } );
1181         equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
1182
1183         function func() {}
1184         jQuery.extend(func, { key: "value" } );
1185         equals( func.key, "value", "Verify a function can be extended" );
1186
1187         var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1188                 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1189                 options1 = { xnumber2: 1, xstring2: "x" },
1190                 options1Copy = { xnumber2: 1, xstring2: "x" },
1191                 options2 = { xstring2: "xx", xxx: "newstringx" },
1192                 options2Copy = { xstring2: "xx", xxx: "newstringx" },
1193                 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
1194
1195         var settings = jQuery.extend({}, defaults, options1, options2);
1196         isObj( settings, merged2, "Check if extended: settings must be extended" );
1197         isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
1198         isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
1199         isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
1200 });
1201
1202 test("val()", function() {
1203         expect(8);
1204
1205         equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
1206         // ticket #1714 this caused a JS error in IE
1207         equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
1208         ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
1209         
1210         equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
1211
1212         isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
1213
1214         equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
1215         
1216         equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
1217         
1218         equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
1219         
1220 });
1221
1222 test("val(String/Number)", function() {
1223         expect(6);
1224         document.getElementById('text1').value = "bla";
1225         equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
1226         
1227         jQuery("#text1").val('test');
1228         equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
1229         
1230         jQuery("#text1").val(67);
1231         equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
1232
1233         jQuery("#select1").val("3");
1234         equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
1235
1236         jQuery("#select1").val(2);
1237         equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
1238
1239         // using contents will get comments regular, text, and comment nodes
1240         var j = jQuery("#nonnodes").contents();
1241         j.val("asdf");
1242         equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
1243         j.removeAttr("value");
1244 });
1245
1246 var scriptorder = 0;
1247
1248 test("html(String)", function() {
1249         expect(13);
1250         var div = jQuery("#main > div");
1251         div.html("<b>test</b>");
1252         var pass = true;
1253         for ( var i = 0; i < div.size(); i++ ) {
1254                 if ( div.get(i).childNodes.length != 1 ) pass = false;
1255         }
1256         ok( pass, "Set HTML" );
1257
1258         reset();
1259         // using contents will get comments regular, text, and comment nodes
1260         var j = jQuery("#nonnodes").contents();
1261         j.html("<b>bold</b>");
1262
1263         // this is needed, or the expando added by jQuery unique will yield a different html
1264         j.find('b').removeData();
1265         equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1266
1267         jQuery("#main").html("<select/>");
1268         jQuery("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
1269         equals( jQuery("#main select").val(), "O2", "Selected option correct" );
1270
1271         var $div = jQuery('<div />');
1272         equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
1273         equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
1274
1275         stop();
1276
1277         jQuery("#main").html('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
1278
1279         jQuery("#main").html('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
1280
1281         // 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
1282         jQuery("#main").html("<script>equals(scriptorder++, 0, 'Script is executed in order');equals(jQuery('#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(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>");
1283
1284         setTimeout( start, 100 );
1285 });
1286
1287 test("filter()", function() {
1288         expect(6);
1289         isSet( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
1290         isSet( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
1291         isSet( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
1292         isSet( jQuery("p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
1293
1294         // using contents will get comments regular, text, and comment nodes
1295         var j = jQuery("#nonnodes").contents();
1296         equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
1297         equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
1298 });
1299
1300 test("not()", function() {
1301         expect(8);
1302         equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
1303         equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
1304         isSet( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
1305         isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
1306         isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
1307         equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
1308         isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')");
1309
1310         var selects = jQuery("#form select");
1311         isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
1312 });
1313
1314 test("andSelf()", function() {
1315         expect(4);
1316         isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
1317         isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
1318         isSet( jQuery("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
1319         isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
1320 });
1321
1322 test("siblings([String])", function() {
1323         expect(5);
1324         isSet( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
1325         isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
1326         isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
1327         isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
1328         isSet( jQuery("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
1329 });
1330
1331 test("children([String])", function() {
1332         expect(3);
1333         isSet( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
1334         isSet( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
1335         isSet( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
1336 });
1337
1338 test("parent([String])", function() {
1339         expect(5);
1340         equals( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
1341         equals( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
1342         equals( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
1343         equals( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
1344         isSet( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
1345 });
1346
1347 test("parents([String])", function() {
1348         expect(5);
1349         equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
1350         equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
1351         equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
1352         isSet( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
1353         isSet( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
1354 });
1355
1356 test("next([String])", function() {
1357         expect(4);
1358         equals( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
1359         equals( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
1360         equals( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
1361         equals( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
1362 });
1363
1364 test("prev([String])", function() {
1365         expect(4);
1366         equals( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
1367         equals( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
1368         equals( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
1369         equals( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
1370 });
1371
1372 test("show()", function() {
1373         expect(15);
1374         var pass = true, div = jQuery("div");
1375         div.show().each(function(){
1376                 if ( this.style.display == "none" ) pass = false;
1377         });
1378         ok( pass, "Show" );
1379
1380         jQuery("#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>');
1381         var test = {
1382                 "div"      : "block",
1383                 "p"        : "block",
1384                 "a"        : "inline",
1385                 "code"     : "inline",
1386                 "pre"      : "block",
1387                 "span"     : "inline",
1388                 "table"    : jQuery.browser.msie ? "block" : "table",
1389                 "thead"    : jQuery.browser.msie ? "block" : "table-header-group",
1390                 "tbody"    : jQuery.browser.msie ? "block" : "table-row-group",
1391                 "tr"       : jQuery.browser.msie ? "block" : "table-row",
1392                 "th"       : jQuery.browser.msie ? "block" : "table-cell",
1393                 "td"       : jQuery.browser.msie ? "block" : "table-cell",
1394                 "ul"       : "block",
1395                 "li"       : jQuery.browser.msie ? "block" : "list-item"
1396         };
1397
1398         jQuery.each(test, function(selector, expected) {
1399                 var elem = jQuery(selector, "#show-tests").show();
1400                 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
1401         });
1402 });
1403
1404 test("addClass(String)", function() {
1405         expect(2);
1406         var div = jQuery("div");
1407         div.addClass("test");
1408         var pass = true;
1409         for ( var i = 0; i < div.size(); i++ ) {
1410          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
1411         }
1412         ok( pass, "Add Class" );
1413
1414         // using contents will get regular, text, and comment nodes
1415         var j = jQuery("#nonnodes").contents();
1416         j.addClass("asdf");
1417         ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
1418 });
1419
1420 test("removeClass(String) - simple", function() {
1421         expect(4);
1422         
1423         var $divs = jQuery('div');
1424         
1425         $divs.addClass("test").removeClass("test");
1426                 
1427         ok( !$divs.is('.test'), "Remove Class" );
1428
1429         reset();
1430         
1431         $divs.addClass("test").addClass("foo").addClass("bar");
1432         $divs.removeClass("test").removeClass("bar").removeClass("foo");
1433         
1434         ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" );
1435
1436         reset();
1437         
1438         $divs.eq(0).addClass("test").removeClass("");
1439         ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" );
1440
1441         // using contents will get regular, text, and comment nodes
1442         var j = jQuery("#nonnodes").contents();
1443         j.removeClass("asdf");
1444         ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
1445 });
1446
1447 test("toggleClass(String)", function() {
1448         expect(3);
1449         var e = jQuery("#firstp");
1450         ok( !e.is(".test"), "Assert class not present" );
1451         e.toggleClass("test");
1452         ok( e.is(".test"), "Assert class present" );
1453         e.toggleClass("test");
1454         ok( !e.is(".test"), "Assert class not present" );
1455 });
1456
1457 test("removeAttr(String", function() {
1458         expect(1);
1459         equals( jQuery('#mark').removeAttr("class")[0].className, "", "remove class" );
1460 });
1461
1462 test("text(String)", function() {
1463         expect(4);
1464         equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML, "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
1465
1466         // using contents will get comments regular, text, and comment nodes
1467         var j = jQuery("#nonnodes").contents();
1468         j.text("hi!");
1469         equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
1470         equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
1471         equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
1472 });
1473
1474 test("jQuery.each(Object,Function)", function() {
1475         expect(12);
1476         jQuery.each( [0,1,2], function(i, n){
1477                 equals( i, n, "Check array iteration" );
1478         });
1479
1480         jQuery.each( [5,6,7], function(i, n){
1481                 equals( i, n - 5, "Check array iteration" );
1482         });
1483
1484         jQuery.each( { name: "name", lang: "lang" }, function(i, n){
1485                 equals( i, n, "Check object iteration" );
1486         });
1487
1488         var total = 0;
1489         jQuery.each([1,2,3], function(i,v){ total += v; });
1490         equals( total, 6, "Looping over an array" );
1491         total = 0;
1492         jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
1493         equals( total, 3, "Looping over an array, with break" );
1494         total = 0;
1495         jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
1496         equals( total, 6, "Looping over an object" );
1497         total = 0;
1498         jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
1499         equals( total, 3, "Looping over an object, with break" );
1500 });
1501
1502 test("jQuery.prop", function() {
1503         expect(2);
1504         var handle = function() { return this.id };
1505         equals( jQuery.prop(jQuery("#ap")[0], handle), "ap", "Check with Function argument" );
1506         equals( jQuery.prop(jQuery("#ap")[0], "value"), "value", "Check with value argument" );
1507 });
1508
1509 test("jQuery.className", function() {
1510         expect(6);
1511         var x = jQuery("<p>Hi</p>")[0];
1512         var c = jQuery.className;
1513         c.add(x, "hi");
1514         equals( x.className, "hi", "Check single added class" );
1515         c.add(x, "foo bar");
1516         equals( x.className, "hi foo bar", "Check more added classes" );
1517         c.remove(x);
1518         equals( x.className, "", "Remove all classes" );
1519         c.add(x, "hi foo bar");
1520         c.remove(x, "foo");
1521         equals( x.className, "hi bar", "Check removal of one class" );
1522         ok( c.has(x, "hi"), "Check has1" );
1523         ok( c.has(x, "bar"), "Check has2" );
1524 });
1525
1526 test("jQuery.data", function() {
1527         expect(5);
1528         var div = jQuery("#foo")[0];
1529         equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
1530         jQuery.data(div, "test", "success");
1531         equals( jQuery.data(div, "test"), "success", "Check for added data" );
1532         jQuery.data(div, "test", "overwritten");
1533         equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );
1534         jQuery.data(div, "test", undefined);
1535         equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");
1536         jQuery.data(div, "test", null);
1537         ok( jQuery.data(div, "test") === null, "Check for null data");
1538 });
1539
1540 test(".data()", function() {
1541         expect(18);
1542         var div = jQuery("#foo");
1543         equals( div.data("test"), undefined, "Check for no data exists" );
1544         div.data("test", "success");
1545         equals( div.data("test"), "success", "Check for added data" );
1546         div.data("test", "overwritten");
1547         equals( div.data("test"), "overwritten", "Check for overwritten data" );
1548         div.data("test", undefined);
1549         equals( div.data("test"), "overwritten", "Check that data wasn't removed");
1550         div.data("test", null);
1551         ok( div.data("test") === null, "Check for null data");
1552
1553         div.data("test", "overwritten");
1554         var hits = {test:0}, gets = {test:0};
1555
1556         div
1557                 .bind("setData",function(e,key,value){ hits[key] += value; })
1558                 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
1559                 .bind("getData",function(e,key){ gets[key] += 1; })
1560                 .bind("getData.foo",function(e,key){ gets[key] += 3; });
1561
1562         div.data("test.foo", 2);
1563         equals( div.data("test"), "overwritten", "Check for original data" );
1564         equals( div.data("test.foo"), 2, "Check for namespaced data" );
1565         equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
1566         equals( hits.test, 2, "Check triggered setter functions" );
1567         equals( gets.test, 5, "Check triggered getter functions" );
1568
1569         hits.test = 0;
1570         gets.test = 0;
1571
1572         div.data("test", 1);
1573         equals( div.data("test"), 1, "Check for original data" );
1574         equals( div.data("test.foo"), 2, "Check for namespaced data" );
1575         equals( div.data("test.bar"), 1, "Check for unmatched namespace" );
1576         equals( hits.test, 1, "Check triggered setter functions" );
1577         equals( gets.test, 5, "Check triggered getter functions" );
1578
1579         hits.test = 0;
1580         gets.test = 0;
1581
1582         div
1583                 .bind("getData",function(e,key){ return key + "root"; })
1584                 .bind("getData.foo",function(e,key){ return key + "foo"; });
1585
1586         equals( div.data("test"), "testroot", "Check for original data" );
1587         equals( div.data("test.foo"), "testfoo", "Check for namespaced data" );
1588         equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
1589 });
1590
1591 test("jQuery.removeData", function() {
1592         expect(1);
1593         var div = jQuery("#foo")[0];
1594         jQuery.data(div, "test", "testing");
1595         jQuery.removeData(div, "test");
1596         equals( jQuery.data(div, "test"), undefined, "Check removal of data" );
1597 });
1598
1599 test(".removeData()", function() {
1600         expect(6);
1601         var div = jQuery("#foo");
1602         div.data("test", "testing");
1603         div.removeData("test");
1604         equals( div.data("test"), undefined, "Check removal of data" );
1605
1606         div.data("test", "testing");
1607         div.data("test.foo", "testing2");
1608         div.removeData("test.bar");
1609         equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
1610         equals( div.data("test"), "testing", "Make sure data is intact" );
1611
1612         div.removeData("test");
1613         equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
1614         equals( div.data("test"), undefined, "Make sure data is intact" );
1615
1616         div.removeData("test.foo");
1617         equals( div.data("test.foo"), undefined, "Make sure data is intact" );
1618 });
1619
1620 test("remove()", function() {
1621         expect(6);
1622         jQuery("#ap").children().remove();
1623         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1624         equals( jQuery("#ap").children().length, 0, "Check remove" );
1625
1626         reset();
1627         jQuery("#ap").children().remove("a");
1628         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1629         equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
1630
1631         // using contents will get comments regular, text, and comment nodes
1632         equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
1633         jQuery("#nonnodes").contents().remove();
1634         equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1635 });
1636
1637 test("empty()", function() {
1638         expect(3);
1639         equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
1640         equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
1641
1642         // using contents will get comments regular, text, and comment nodes
1643         var j = jQuery("#nonnodes").contents();
1644         j.empty();
1645         equals( j.html(), "", "Check node,textnode,comment empty works" );
1646 });
1647
1648 test("slice()", function() {
1649         expect(6);
1650         
1651         var $links = jQuery("#ap a");
1652         
1653         isSet( $links.slice(1,2), q("groups"), "slice(1,2)" );
1654         isSet( $links.slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1655         isSet( $links.slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1656         isSet( $links.slice(-1), q("mark"), "slice(-1)" );
1657
1658         isSet( $links.eq(1), q("groups"), "eq(1)" );
1659         
1660         isSet( $links.eq('2'), q("anchor1"), "eq('2')" );
1661 });
1662
1663 test("map()", function() {
1664         expect(2);//expect(6);
1665
1666         isSet(
1667                 jQuery("#ap").map(function(){
1668                         return jQuery(this).find("a").get();
1669                 }),
1670                 q("google", "groups", "anchor1", "mark"),
1671                 "Array Map"
1672         );
1673
1674         isSet(
1675                 jQuery("#ap > a").map(function(){
1676                         return this.parentNode;
1677                 }),
1678                 q("ap","ap","ap"),
1679                 "Single Map"
1680         );
1681
1682         return;//these haven't been accepted yet
1683
1684         //for #2616
1685         var keys = jQuery.map( {a:1,b:2}, function( v, k ){
1686                 return k;
1687         }, [ ] );
1688
1689         equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
1690
1691         var values = jQuery.map( {a:1,b:2}, function( v, k ){
1692                 return v;
1693         }, [ ] );
1694
1695         equals( values.join(""), "12", "Map the values from a hash to an array" );
1696
1697         var scripts = document.getElementsByTagName("script");
1698         var mapped = jQuery.map( scripts, function( v, k ){
1699                 return v;
1700         }, {length:0} );
1701
1702         equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
1703
1704         var flat = jQuery.map( Array(4), function( v, k ){
1705                 return k % 2 ? k : [k,k,k];//try mixing array and regular returns
1706         });
1707
1708         equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
1709 });
1710
1711 test("contents()", function() {
1712         expect(12);
1713         equals( jQuery("#ap").contents().length, 9, "Check element contents" );
1714         ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" );
1715         var ibody = jQuery("#loadediframe").contents()[0].body;
1716         ok( ibody, "Check existance of IFrame body" );
1717
1718         equals( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1719
1720         jQuery(ibody).append("<div>init text</div>");
1721         equals( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1722
1723         equals( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1724
1725         jQuery("div:last", ibody).text("div text");
1726         equals( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1727
1728         jQuery("div:last", ibody).remove();
1729         equals( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1730
1731         equals( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1732
1733         jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1734         jQuery("table", ibody).remove();
1735         equals( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
1736
1737         // using contents will get comments regular, text, and comment nodes
1738         var c = jQuery("#nonnodes").contents().contents();
1739         equals( c.length, 1, "Check node,textnode,comment contents is just one" );
1740         equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
1741 });
1742
1743 test("jQuery.makeArray", function(){
1744         expect(15);
1745
1746         equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" );
1747
1748         equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
1749
1750         equals( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
1751
1752         equals( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
1753
1754         equals( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
1755
1756         equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
1757
1758         equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
1759
1760         equals( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
1761
1762         equals( jQuery.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
1763
1764         equals( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
1765
1766         ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
1767
1768         // function, is tricky as it has length
1769         equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
1770         
1771         //window, also has length
1772         equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
1773
1774         equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
1775
1776         ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
1777 });