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