Fixed #1095 bug where radio buttons became unchecked during show(). Also added unit...
[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("$()", function() {
15         expect(5);
16         
17         var main = $("#main");
18         isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
19         
20         // make sure this is handled
21         $('<p>\r\n</p>');
22         ok( true, "Check for \\r and \\n in jQuery()" );
23         
24         /* // Disabled until we add this functionality in
25         var pass = true;
26         try {
27                 $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
28         } catch(e){
29                 pass = false;
30         }
31         ok( pass, "$('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
32
33         var code = $("<code/>");
34         equals( code.length, 1, "Correct number of elements generated for code" );
35         var img = $("<img/>");
36         equals( img.length, 1, "Correct number of elements generated for img" );
37         var div = $("<div/><hr/><code/><b/>");
38         equals( div.length, 4, "Correct number of elements generated for div hr code b" );
39 });
40
41 test("noConflict", function() {
42         expect(6);
43         
44         var old = jQuery;
45         var newjQuery = jQuery.noConflict();
46
47         ok( newjQuery == old, "noConflict returned the jQuery object" );
48         ok( jQuery == old, "Make sure jQuery wasn't touched." );
49         ok( $ == "$", "Make sure $ was reverted." );
50
51         jQuery = $ = old;
52
53         newjQuery = jQuery.noConflict(true);
54
55         ok( newjQuery == old, "noConflict returned the jQuery object" );
56         ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
57         ok( $ == "$", "Make sure $ was reverted." );
58
59         jQuery = $ = old;
60 });
61
62 test("isFunction", function() {
63         expect(21);
64
65         // Make sure that false values return false
66         ok( !jQuery.isFunction(), "No Value" );
67         ok( !jQuery.isFunction( null ), "null Value" );
68         ok( !jQuery.isFunction( undefined ), "undefined Value" );
69         ok( !jQuery.isFunction( "" ), "Empty String Value" );
70         ok( !jQuery.isFunction( 0 ), "0 Value" );
71
72         // Check built-ins
73         // Safari uses "(Internal Function)"
74         ok( jQuery.isFunction(String), "String Function" );
75         ok( jQuery.isFunction(Array), "Array Function" );
76         ok( jQuery.isFunction(Object), "Object Function" );
77         ok( jQuery.isFunction(Function), "Function Function" );
78
79         // When stringified, this could be misinterpreted
80         var mystr = "function";
81         ok( !jQuery.isFunction(mystr), "Function String" );
82
83         // When stringified, this could be misinterpreted
84         var myarr = [ "function" ];
85         ok( !jQuery.isFunction(myarr), "Function Array" );
86
87         // When stringified, this could be misinterpreted
88         var myfunction = { "function": "test" };
89         ok( !jQuery.isFunction(myfunction), "Function Object" );
90
91         // Make sure normal functions still work
92         var fn = function(){};
93         ok( jQuery.isFunction(fn), "Normal Function" );
94
95         var obj = document.createElement("object");
96
97         // Firefox says this is a function
98         ok( !jQuery.isFunction(obj), "Object Element" );
99
100         // IE says this is an object
101         ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
102
103         var nodes = document.body.childNodes;
104
105         // Safari says this is a function
106         ok( !jQuery.isFunction(nodes), "childNodes Property" );
107
108         var first = document.body.firstChild;
109         
110         // Normal elements are reported ok everywhere
111         ok( !jQuery.isFunction(first), "A normal DOM Element" );
112
113         var input = document.createElement("input");
114         input.type = "text";
115         document.body.appendChild( input );
116
117         // IE says this is an object
118         ok( jQuery.isFunction(input.focus), "A default function property" );
119
120         document.body.removeChild( input );
121
122         var a = document.createElement("a");
123         a.href = "some-function";
124         document.body.appendChild( a );
125
126         // This serializes with the word 'function' in it
127         ok( !jQuery.isFunction(a), "Anchor Element" );
128
129         document.body.removeChild( a );
130
131         // Recursive function calls have lengths and array-like properties
132         function callme(callback){
133                 function fn(response){
134                         callback(response);
135                 }
136
137                 ok( jQuery.isFunction(fn), "Recursive Function Call" );
138
139         fn({ some: "data" });
140         };
141
142         callme(function(){
143         callme(function(){});
144         });
145 });
146
147 var foo = false;
148
149 test("$('html')", function() {
150         expect(4);
151         
152         reset();
153         foo = false;
154         var s = $("<script>var foo='test';</script>")[0];
155         ok( s, "Creating a script" );
156         ok( !foo, "Make sure the script wasn't executed prematurely" );
157         $("body").append(s);
158         ok( foo, "Executing a scripts contents in the right context" );
159         
160         reset();
161         ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
162         
163         reset();
164 });
165
166 test("length", function() {
167         expect(1);
168         ok( $("p").length == 6, "Get Number of Elements Found" );
169 });
170
171 test("size()", function() {
172         expect(1);
173         ok( $("p").size() == 6, "Get Number of Elements Found" );
174 });
175
176 test("get()", function() {
177         expect(1);
178         isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
179 });
180
181 test("get(Number)", function() {
182         expect(1);
183         ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
184 });
185
186 test("add(String|Element|Array)", function() {
187         expect(7);
188         isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
189         isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
190         ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
191         
192         var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
193         ok( x[0].id == "x1", "Check on-the-fly element1" );
194         ok( x[1].id == "x2", "Check on-the-fly element2" );
195         
196         var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
197         ok( x[0].id == "x1", "Check on-the-fly element1" );
198         ok( x[1].id == "x2", "Check on-the-fly element2" );
199 });
200
201 test("each(Function)", function() {
202         expect(1);
203         var div = $("div");
204         div.each(function(){this.foo = 'zoo';});
205         var pass = true;
206         for ( var i = 0; i < div.size(); i++ ) {
207           if ( div.get(i).foo != "zoo" ) pass = false;
208         }
209         ok( pass, "Execute a function, Relative" );
210 });
211
212 test("index(Object)", function() {
213         expect(8);
214         ok( $([window, document]).index(window) == 0, "Check for index of elements" );
215         ok( $([window, document]).index(document) == 1, "Check for index of elements" );
216         var inputElements = $('#radio1,#radio2,#check1,#check2');
217         ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
218         ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
219         ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
220         ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
221         ok( inputElements.index(window) == -1, "Check for not found index" );
222         ok( inputElements.index(document) == -1, "Check for not found index" );
223 });
224
225 test("attr(String)", function() {
226         expect(13);
227         ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
228         ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
229         ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
230         ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
231         ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
232         ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
233         ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
234         ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
235         ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
236         ok( $('#name').attr('name') == "name", 'Check for name attribute' );
237         ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
238         ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
239         
240         $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
241         ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
242 });
243
244 if ( !isLocal ) {
245     test("attr(String) in XML Files", function() {
246         expect(2);
247         stop();
248         $.get("data/dashboard.xml", function(xml) {
249             ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
250             ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
251             start();
252         });
253     });
254 }
255
256 test("attr(String, Function)", function() {
257         expect(2);
258         ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
259         ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
260 });
261
262 test("attr(Hash)", function() {
263         expect(1);
264         var pass = true;
265         $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
266           if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
267         });
268         ok( pass, "Set Multiple Attributes" );
269 });
270
271 test("attr(String, Object)", function() {
272         expect(12);
273         var div = $("div");
274         div.attr("foo", "bar");
275         var pass = true;
276         for ( var i = 0; i < div.size(); i++ ) {
277           if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
278         }
279         ok( pass, "Set Attribute" );
280
281         ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );    
282         
283         $("#name").attr('name', 'something');
284         ok( $("#name").attr('name') == 'something', 'Set name attribute' );
285         $("#check2").attr('checked', true);
286         ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
287         $("#check2").attr('checked', false);
288         ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
289         $("#text1").attr('readonly', true);
290         ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
291         $("#text1").attr('readonly', false);
292         ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
293         $("#name").attr('maxlength', '5');
294         ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
295
296         reset();
297
298         var type = $("#check2").attr('type');
299         var thrown = false;
300         try {
301                 $("#check2").attr('type','hidden');
302         } catch(e) {
303                 thrown = true;
304         }
305         ok( thrown, "Exception thrown when trying to change type property" );
306         equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
307
308         var check = document.createElement("input");
309         var thrown = true;
310         try {
311                 $(check).attr('type','checkbox');
312         } catch(e) {
313                 thrown = false;
314         }
315         ok( thrown, "Exception thrown when trying to change type property" );
316         equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
317 });
318
319 if ( !isLocal ) {
320     test("attr(String, Object) - Loaded via XML document", function() {
321         expect(2);
322         stop();
323         $.get('data/dashboard.xml', function(xml) { 
324               var titles = [];
325               $('tab', xml).each(function() {
326                     titles.push($(this).attr('title'));
327               });
328               ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
329               ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
330               start();
331         });
332     });
333 }
334
335 test("css(String|Hash)", function() {
336         expect(19);
337         
338         ok( $('#main').css("display") == 'none', 'Check for css property "display"');
339         
340         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
341         $('#foo').css({display: 'none'});
342         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
343         $('#foo').css({display: 'block'});
344         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
345         
346         $('#floatTest').css({styleFloat: 'right'});
347         ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
348         $('#floatTest').css({cssFloat: 'left'});
349         ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
350         $('#floatTest').css({'float': 'right'});
351         ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
352         $('#floatTest').css({'font-size': '30px'});
353         ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
354         
355         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
356                 $('#foo').css({opacity: n});
357                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
358                 $('#foo').css({opacity: parseFloat(n)});
359                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
360         });     
361         $('#foo').css({opacity: ''});
362         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
363 });
364
365 test("css(String, Object)", function() {
366         expect(18);
367         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
368         $('#foo').css('display', 'none');
369         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
370         $('#foo').css('display', 'block');
371         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
372         
373         $('#floatTest').css('styleFloat', 'left');
374         ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
375         $('#floatTest').css('cssFloat', 'right');
376         ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
377         $('#floatTest').css('float', 'left');
378         ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
379         $('#floatTest').css('font-size', '20px');
380         ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
381         
382         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
383                 $('#foo').css('opacity', n);
384                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
385                 $('#foo').css('opacity', parseFloat(n));
386                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
387         });
388         $('#foo').css('opacity', '');
389         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
390 });
391
392 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
393         expect(4);
394
395         var $checkedtest = $("#checkedtest");
396         // IE6 was clearing "checked" in jQuery.css(elem, "height");
397         jQuery.css($checkedtest[0], "height");
398         ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
399         ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
400         ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
401         ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
402 });
403
404 test("text()", function() {
405         expect(1);
406         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
407         ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
408 });
409
410 test("wrap(String|Element)", function() {
411         expect(6);
412         var defaultText = 'Try them out:'
413         var result = $('#first').wrap('<div class="red"><span></span></div>').text();
414         ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
415         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
416
417         reset();
418         var defaultText = 'Try them out:'
419         var result = $('#first').wrap(document.getElementById('empty')).parent();
420         ok( result.is('ol'), 'Check for element wrapping' );
421         ok( result.text() == defaultText, 'Check for element wrapping' );
422         
423         reset();
424         $('#check1').click(function() {         
425                 var checkbox = this;            
426                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
427                 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
428                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
429         }).click();
430 });
431
432 test("wrapAll(String|Element)", function() {
433         expect(8);
434         var prev = $("#first")[0].previousSibling;
435         var p = $("#first")[0].parentNode;
436         var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
437         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
438         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
439         ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
440         equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
441         equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
442
443         reset();
444         var prev = $("#first")[0].previousSibling;
445         var p = $("#first")[0].parentNode;
446         var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
447         equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
448         equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
449         equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
450 });
451
452 test("wrapInner(String|Element)", function() {
453         expect(6);
454         var num = $("#first").children().length;
455         var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
456         equals( $("#first").children().length, 1, "Only one child" );
457         ok( $("#first").children().is(".red"), "Verify Right Element" );
458         equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
459
460         reset();
461         var num = $("#first").children().length;
462         var result = $('#first').wrapInner(document.getElementById('empty'));
463         equals( $("#first").children().length, 1, "Only one child" );
464         ok( $("#first").children().is("#empty"), "Verify Right Element" );
465         equals( $("#first").children().children().length, num, "Verify Elements Intact" );
466 });
467
468 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
469         expect(18);
470         var defaultText = 'Try them out:'
471         var result = $('#first').append('<b>buga</b>');
472         ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
473         ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
474         
475         reset();
476         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
477         $('#sap').append(document.getElementById('first'));
478         ok( expected == $('#sap').text(), "Check for appending of element" );
479         
480         reset();
481         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
482         $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
483         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
484         
485         reset();
486         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
487         $('#sap').append($("#first, #yahoo"));
488         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
489
490         reset();
491         $("#sap").append( 5 );
492         ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
493
494         reset();
495         $("#sap").append( " text with spaces " );
496         ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
497
498         reset();
499         ok( $("#sap").append([]), "Check for appending an empty array." );
500         ok( $("#sap").append(""), "Check for appending an empty string." );
501         ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
502         
503         reset();
504         $("#sap").append(document.getElementById('form'));
505         ok( $("#sap>form").size() == 1, "Check for appending a form" );  // Bug #910
506
507         reset();
508         var pass = true;
509         try {
510                 $( $("iframe")[0].contentWindow.document.body ).append("<div>test</div>");
511         } catch(e) {
512                 pass = false;
513         }
514
515         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
516         
517         reset();
518         $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
519         t( 'Append legend', '#legend', ['legend'] );
520         
521         reset();
522         $('#select1').append('<OPTION>Test</OPTION>');
523         ok( $('#select1 option:last').text() == "Test", "Appending &lt;OPTION&gt; (all caps)" );
524         
525         $('#table').append('<colgroup></colgroup>');
526         ok( $('#table colgroup').length, "Append colgroup" );
527         
528         $('#table colgroup').append('<col/>');
529         ok( $('#table colgroup col').length, "Append col" );
530         
531         reset();
532         $('#table').append('<caption></caption>');
533         ok( $('#table caption').length, "Append caption" );
534
535         reset();
536         $('form:last')
537                 .append('<select id="appendSelect1"></select>')
538                 .append('<select id="appendSelect2"><option>Test</option></select>');
539         
540         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
541 });
542
543 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
544         expect(6);
545         var defaultText = 'Try them out:'
546         $('<b>buga</b>').appendTo('#first');
547         ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
548         ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
549         
550         reset();
551         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
552         $(document.getElementById('first')).appendTo('#sap');
553         ok( expected == $('#sap').text(), "Check for appending of element" );
554         
555         reset();
556         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
557         $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
558         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
559         
560         reset();
561         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
562         $("#first, #yahoo").appendTo('#sap');
563         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
564         
565         reset();
566         $('#select1').appendTo('#foo');
567         t( 'Append select', '#foo select', ['select1'] );
568 });
569
570 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
571         expect(5);
572         var defaultText = 'Try them out:'
573         var result = $('#first').prepend('<b>buga</b>');
574         ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
575         ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
576         
577         reset();
578         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
579         $('#sap').prepend(document.getElementById('first'));
580         ok( expected == $('#sap').text(), "Check for prepending of element" );
581
582         reset();
583         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
584         $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
585         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
586         
587         reset();
588         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
589         $('#sap').prepend($("#first, #yahoo"));
590         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
591 });
592
593 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
594         expect(6);
595         var defaultText = 'Try them out:'
596         $('<b>buga</b>').prependTo('#first');
597         ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
598         ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
599         
600         reset();
601         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
602         $(document.getElementById('first')).prependTo('#sap');
603         ok( expected == $('#sap').text(), "Check for prepending of element" );
604
605         reset();
606         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
607         $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
608         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
609         
610         reset();
611         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
612         $("#yahoo, #first").prependTo('#sap');
613         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
614         
615         reset();
616         $('<select id="prependSelect1"></select>').prependTo('form:last');
617         $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
618         
619         t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
620 });
621
622 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
623         expect(4);
624         var expected = 'This is a normal link: bugaYahoo';
625         $('#yahoo').before('<b>buga</b>');
626         ok( expected == $('#en').text(), 'Insert String before' );
627         
628         reset();
629         expected = "This is a normal link: Try them out:Yahoo";
630         $('#yahoo').before(document.getElementById('first'));
631         ok( expected == $('#en').text(), "Insert element before" );
632         
633         reset();
634         expected = "This is a normal link: Try them out:diveintomarkYahoo";
635         $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
636         ok( expected == $('#en').text(), "Insert array of elements before" );
637         
638         reset();
639         expected = "This is a normal link: Try them out:diveintomarkYahoo";
640         $('#yahoo').before($("#first, #mark"));
641         ok( expected == $('#en').text(), "Insert jQuery before" );
642 });
643
644 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
645         expect(4);
646         var expected = 'This is a normal link: bugaYahoo';
647         $('<b>buga</b>').insertBefore('#yahoo');
648         ok( expected == $('#en').text(), 'Insert String before' );
649         
650         reset();
651         expected = "This is a normal link: Try them out:Yahoo";
652         $(document.getElementById('first')).insertBefore('#yahoo');
653         ok( expected == $('#en').text(), "Insert element before" );
654         
655         reset();
656         expected = "This is a normal link: Try them out:diveintomarkYahoo";
657         $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
658         ok( expected == $('#en').text(), "Insert array of elements before" );
659         
660         reset();
661         expected = "This is a normal link: Try them out:diveintomarkYahoo";
662         $("#first, #mark").insertBefore('#yahoo');
663         ok( expected == $('#en').text(), "Insert jQuery before" );
664 });
665
666 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
667         expect(4);
668         var expected = 'This is a normal link: Yahoobuga';
669         $('#yahoo').after('<b>buga</b>');
670         ok( expected == $('#en').text(), 'Insert String after' );
671         
672         reset();
673         expected = "This is a normal link: YahooTry them out:";
674         $('#yahoo').after(document.getElementById('first'));
675         ok( expected == $('#en').text(), "Insert element after" );
676
677         reset();
678         expected = "This is a normal link: YahooTry them out:diveintomark";
679         $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
680         ok( expected == $('#en').text(), "Insert array of elements after" );
681         
682         reset();
683         expected = "This is a normal link: YahooTry them out:diveintomark";
684         $('#yahoo').after($("#first, #mark"));
685         ok( expected == $('#en').text(), "Insert jQuery after" );
686 });
687
688 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
689         expect(4);
690         var expected = 'This is a normal link: Yahoobuga';
691         $('<b>buga</b>').insertAfter('#yahoo');
692         ok( expected == $('#en').text(), 'Insert String after' );
693         
694         reset();
695         expected = "This is a normal link: YahooTry them out:";
696         $(document.getElementById('first')).insertAfter('#yahoo');
697         ok( expected == $('#en').text(), "Insert element after" );
698
699         reset();
700         expected = "This is a normal link: YahooTry them out:diveintomark";
701         $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
702         ok( expected == $('#en').text(), "Insert array of elements after" );
703         
704         reset();
705         expected = "This is a normal link: YahooTry them out:diveintomark";
706         $("#mark, #first").insertAfter('#yahoo');
707         ok( expected == $('#en').text(), "Insert jQuery after" );
708 });
709
710 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
711         expect(10);
712         $('#yahoo').replaceWith('<b id="replace">buga</b>');
713         ok( $("#replace")[0], 'Replace element with string' );
714         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
715         
716         reset();
717         $('#yahoo').replaceWith(document.getElementById('first'));
718         ok( $("#first")[0], 'Replace element with element' );
719         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
720
721         reset();
722         $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
723         ok( $("#first")[0], 'Replace element with array of elements' );
724         ok( $("#mark")[0], 'Replace element with array of elements' );
725         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
726         
727         reset();
728         $('#yahoo').replaceWith($("#first, #mark"));
729         ok( $("#first")[0], 'Replace element with set of elements' );
730         ok( $("#mark")[0], 'Replace element with set of elements' );
731         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
732 });
733
734 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
735         expect(10);
736         $('<b id="replace">buga</b>').replaceAll("#yahoo");
737         ok( $("#replace")[0], 'Replace element with string' );
738         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
739         
740         reset();
741         $(document.getElementById('first')).replaceAll("#yahoo");
742         ok( $("#first")[0], 'Replace element with element' );
743         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
744
745         reset();
746         $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
747         ok( $("#first")[0], 'Replace element with array of elements' );
748         ok( $("#mark")[0], 'Replace element with array of elements' );
749         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
750         
751         reset();
752         $("#first, #mark").replaceAll("#yahoo");
753         ok( $("#first")[0], 'Replace element with set of elements' );
754         ok( $("#mark")[0], 'Replace element with set of elements' );
755         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
756 });
757
758 test("end()", function() {
759         expect(3);
760         ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
761         ok( $('#yahoo').end(), 'Check for end with nothing to end' );
762         
763         var x = $('#yahoo');
764         x.parent();
765         ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
766 });
767
768 test("find(String)", function() {
769         expect(1);
770         ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
771 });
772
773 test("clone()", function() {
774         expect(3);
775         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
776         var clone = $('#yahoo').clone();
777         ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
778         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
779 });
780
781 test("is(String)", function() {
782         expect(26);
783         ok( $('#form').is('form'), 'Check for element: A form must be a form' );
784         ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
785         ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
786         ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
787         ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
788         ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
789         ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
790         ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
791         ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
792         ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
793         ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
794         ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
795         ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
796         ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
797         ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
798         ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
799         ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
800         ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
801         ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
802         ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
803         ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
804         ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
805         
806         // test is() with comma-seperated expressions
807         ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
808         ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
809         ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
810         ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
811 });
812
813 test("$.extend(Object, Object)", function() {
814         expect(11);
815
816         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
817                 options =     { xnumber2: 1, xstring2: "x", xxx: "newstring" },
818                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
819                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
820                 deep1 = { foo: { bar: true } },
821                 deep1copy = { foo: { bar: true } },
822                 deep2 = { foo: { baz: true }, foo2: document },
823                 deep2copy = { foo: { baz: true }, foo2: document },
824                 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
825
826         jQuery.extend(settings, options);
827         isObj( settings, merged, "Check if extended: settings must be extended" );
828         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
829
830         jQuery.extend(settings, null, options);
831         isObj( settings, merged, "Check if extended: settings must be extended" );
832         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
833
834         jQuery.extend(true, deep1, deep2);
835         isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
836         isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
837         equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
838
839         var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
840                 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
841                 options1 =     { xnumber2: 1, xstring2: "x" },
842                 options1Copy = { xnumber2: 1, xstring2: "x" },
843                 options2 =     { xstring2: "xx", xxx: "newstringx" },
844                 options2Copy = { xstring2: "xx", xxx: "newstringx" },
845                 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
846
847         var settings = jQuery.extend({}, defaults, options1, options2);
848         isObj( settings, merged2, "Check if extended: settings must be extended" );
849         isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
850         isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
851         isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
852 });
853
854 test("val()", function() {
855         expect(2);
856         ok( $("#text1").val() == "Test", "Check for value of input element" );
857         ok( !$("#text1").val() == "", "Check for value of input element" );
858 });
859
860 test("val(String)", function() {
861         expect(3);
862         document.getElementById('text1').value = "bla";
863         ok( $("#text1").val() == "bla", "Check for modified value of input element" );
864         $("#text1").val('test');
865         ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
866         
867         $("#select1").val("3");
868         ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
869 });
870
871 var scriptorder = 0;
872
873 test("html(String)", function() {
874         expect(9);
875         var div = $("div");
876         div.html("<b>test</b>");
877         var pass = true;
878         for ( var i = 0; i < div.size(); i++ ) {
879           if ( div.get(i).childNodes.length == 0 ) pass = false;
880         }
881         ok( pass, "Set HTML" );
882
883         stop();
884
885         $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
886
887         $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
888
889         $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 0,'Execute before html')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
890
891         setTimeout( start, 100 );
892 });
893
894 test("filter()", function() {
895         expect(4);
896         isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
897         isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
898         isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
899         isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
900 });
901
902 test("not()", function() {
903         expect(3);
904         ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
905         isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
906         isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
907 });
908
909 test("andSelf()", function() {
910         expect(4);
911         isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
912         isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
913         isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
914         isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
915 });
916
917 test("siblings([String])", function() {
918         expect(5);
919         isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
920         isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 
921         isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
922         isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
923         isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
924 });
925
926 test("children([String])", function() {
927         expect(3);
928         isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
929         isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
930         isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
931 });
932
933 test("parent([String])", function() {
934         expect(5);
935         ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
936         ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
937         ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
938         ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
939         isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
940 });
941         
942 test("parents([String])", function() {
943         expect(5);
944         ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
945         ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
946         ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
947         isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
948         isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
949 });
950
951 test("next([String])", function() {
952         expect(4);
953         ok( $("#ap").next()[0].id == "foo", "Simple next check" );
954         ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
955         ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
956         ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
957 });
958         
959 test("prev([String])", function() {
960         expect(4);
961         ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
962         ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
963         ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
964         ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
965 });
966
967 test("show()", function() {
968         expect(1);
969         var pass = true, div = $("div");
970         div.show().each(function(){
971           if ( this.style.display == "none" ) pass = false;
972         });
973         ok( pass, "Show" );
974 });
975
976 test("addClass(String)", function() {
977         expect(1);
978         var div = $("div");
979         div.addClass("test");
980         var pass = true;
981         for ( var i = 0; i < div.size(); i++ ) {
982          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
983         }
984         ok( pass, "Add Class" );
985 });
986
987 test("removeClass(String) - simple", function() {
988         expect(3);
989         var div = $("div").addClass("test").removeClass("test"),
990                 pass = true;
991         for ( var i = 0; i < div.size(); i++ ) {
992                 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
993         }
994         ok( pass, "Remove Class" );
995         
996         reset();
997         var div = $("div").addClass("test").addClass("foo").addClass("bar");
998         div.removeClass("test").removeClass("bar").removeClass("foo");
999         var pass = true;
1000         for ( var i = 0; i < div.size(); i++ ) {
1001          if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
1002         }
1003         ok( pass, "Remove multiple classes" );
1004         
1005         reset();
1006         var div = $("div:eq(0)").addClass("test").removeClass("");
1007         ok( div.is('.test'), "Empty string passed to removeClass" );
1008         
1009 });
1010
1011 test("toggleClass(String)", function() {
1012         expect(3);
1013         var e = $("#firstp");
1014         ok( !e.is(".test"), "Assert class not present" );
1015         e.toggleClass("test");
1016         ok( e.is(".test"), "Assert class present" ); 
1017         e.toggleClass("test");
1018         ok( !e.is(".test"), "Assert class not present" );
1019 });
1020
1021 test("removeAttr(String", function() {
1022         expect(1);
1023         ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
1024 });
1025
1026 test("text(String)", function() {
1027         expect(1);
1028         ok( $("#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" );
1029 });
1030
1031 test("$.each(Object,Function)", function() {
1032         expect(8);
1033         $.each( [0,1,2], function(i, n){
1034                 ok( i == n, "Check array iteration" );
1035         });
1036         
1037         $.each( [5,6,7], function(i, n){
1038                 ok( i == n - 5, "Check array iteration" );
1039         });
1040          
1041         $.each( { name: "name", lang: "lang" }, function(i, n){
1042                 ok( i == n, "Check object iteration" );
1043         });
1044 });
1045
1046 test("$.prop", function() {
1047         expect(2);
1048         var handle = function() { return this.id };
1049         ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
1050         ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
1051 });
1052
1053 test("$.className", function() {
1054         expect(6);
1055         var x = $("<p>Hi</p>")[0];
1056         var c = $.className;
1057         c.add(x, "hi");
1058         ok( x.className == "hi", "Check single added class" );
1059         c.add(x, "foo bar");
1060         ok( x.className == "hi foo bar", "Check more added classes" );
1061         c.remove(x);
1062         ok( x.className == "", "Remove all classes" );
1063         c.add(x, "hi foo bar");
1064         c.remove(x, "foo");
1065         ok( x.className == "hi bar", "Check removal of one class" );
1066         ok( c.has(x, "hi"), "Check has1" );
1067         ok( c.has(x, "bar"), "Check has2" );
1068 });
1069
1070 test("remove()", function() {
1071         expect(4);
1072         $("#ap").children().remove();
1073         ok( $("#ap").text().length > 10, "Check text is not removed" );
1074         ok( $("#ap").children().length == 0, "Check remove" );
1075         
1076         reset();
1077         $("#ap").children().remove("a");
1078         ok( $("#ap").text().length > 10, "Check text is not removed" );
1079         ok( $("#ap").children().length == 1, "Check filtered remove" );
1080 });
1081
1082 test("empty()", function() {
1083         expect(2);
1084         ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
1085         ok( $("#ap").children().length == 4, "Check elements are not removed" );
1086 });
1087
1088 test("slice()", function() {
1089         expect(5);
1090         isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
1091         isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1092         isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1093         isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
1094
1095         isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
1096 });
1097
1098 test("map()", function() {
1099         expect(2);
1100
1101         isSet(
1102                 $("#ap").map(function(){
1103                         return $(this).find("a").get();
1104                 }),
1105                 q("google", "groups", "anchor1", "mark"),
1106                 "Array Map"
1107         );
1108
1109         isSet(
1110                 $("#ap > a").map(function(){
1111                         return this.parentNode;
1112                 }),
1113                 q("ap","ap","ap"),
1114                 "Single Map"
1115         );
1116 });
1117
1118 test("contents()", function() {
1119         expect(2);
1120         equals( $("#ap").contents().length, 9, "Check element contents" );
1121         ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
1122         // Disabled, randomly fails
1123         //ok( $("#iframe").contents()[0].body, "Check existance of IFrame body" );
1124 });