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