3 test("Basic requirements", function() {
\r
5 ok( Array.prototype.push, "Array.push()" );
\r
6 ok( Function.prototype.apply, "Function.apply()" );
\r
7 ok( document.getElementById, "getElementById" );
\r
8 ok( document.getElementsByTagName, "getElementsByTagName" );
\r
9 ok( RegExp, "RegExp" );
\r
10 ok( jQuery, "jQuery" );
\r
14 test("$()", function() {
17 var main = $("#main");
\r
18 isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
\r
20 // make sure this is handled
\r
22 ok( true, "Check for \\r and \\n in jQuery()" );
26 var f = document.getElementById("iframe").contentDocument;
\r
28 f.write("<html><body></body></html>");
\r
30 $("<div>Testing</div>").appendTo(f.body);
\r
34 ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );
\r
37 test("isFunction", function() {
\r
40 // Make sure that false values return false
\r
41 ok( !jQuery.isFunction(), "No Value" );
\r
42 ok( !jQuery.isFunction( null ), "null Value" );
\r
43 ok( !jQuery.isFunction( undefined ), "undefined Value" );
\r
44 ok( !jQuery.isFunction( "" ), "Empty String Value" );
\r
45 ok( !jQuery.isFunction( 0 ), "0 Value" );
\r
48 // Safari uses "(Internal Function)"
\r
49 ok( jQuery.isFunction(String), "String Function" );
\r
50 ok( jQuery.isFunction(Array), "Array Function" );
\r
51 ok( jQuery.isFunction(Object), "Object Function" );
\r
52 ok( jQuery.isFunction(Function), "Function Function" );
\r
54 // When stringified, this could be misinterpreted
\r
55 var mystr = "function";
\r
56 ok( !jQuery.isFunction(mystr), "Function String" );
\r
58 // When stringified, this could be misinterpreted
\r
59 var myarr = [ "function" ];
\r
60 ok( !jQuery.isFunction(myarr), "Function Array" );
\r
62 // When stringified, this could be misinterpreted
\r
63 var myfunction = { "function": "test" };
\r
64 ok( !jQuery.isFunction(myfunction), "Function Object" );
\r
66 // Make sure normal functions still work
\r
67 var fn = function(){};
\r
68 ok( jQuery.isFunction(fn), "Normal Function" );
\r
70 var obj = document.createElement("object");
\r
72 // Firefox says this is a function
\r
73 ok( !jQuery.isFunction(obj), "Object Element" );
\r
75 // IE says this is an object
\r
76 ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
\r
78 var nodes = document.body.childNodes;
\r
80 // Safari says this is a function
\r
81 ok( !jQuery.isFunction(nodes), "childNodes Property" );
\r
83 var first = document.body.firstChild;
\r
85 // Normal elements are reported ok everywhere
\r
86 ok( !jQuery.isFunction(first), "A normal DOM Element" );
\r
88 var input = document.createElement("input");
\r
89 input.type = "text";
\r
90 document.body.appendChild( input );
\r
92 // IE says this is an object
\r
93 ok( jQuery.isFunction(input.focus), "A default function property" );
\r
95 document.body.removeChild( input );
\r
97 var a = document.createElement("a");
\r
98 a.href = "some-function";
\r
99 document.body.appendChild( a );
\r
101 // This serializes with the word 'function' in it
\r
102 ok( !jQuery.isFunction(a), "Anchor Element" );
\r
104 document.body.removeChild( a );
\r
106 // Recursive function calls have lengths and array-like properties
\r
107 function callme(callback){
\r
108 function fn(response){
\r
109 callback(response);
\r
112 ok( jQuery.isFunction(fn), "Recursive Function Call" );
\r
114 fn({ some: "data" });
\r
118 callme(function(){});
\r
122 test("length", function() {
124 ok( $("div").length == 2, "Get Number of Elements Found" );
\r
127 test("size()", function() {
129 ok( $("div").size() == 2, "Get Number of Elements Found" );
\r
132 test("get()", function() {
134 isSet( $("div").get(), q("main","foo"), "Get All Elements" );
\r
137 test("get(Number)", function() {
139 ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
\r
142 test("add(String|Element|Array)", function() {
144 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
145 isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
146 ok( $([]).add($("#form")[0].elements).length > 13, "Check elements from array" );
\r
148 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
\r
149 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
150 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
152 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
153 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
154 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
157 test("each(Function)", function() {
\r
159 var div = $("div");
\r
160 div.each(function(){this.foo = 'zoo';});
\r
162 for ( var i = 0; i < div.size(); i++ ) {
\r
163 if ( div.get(i).foo != "zoo" ) pass = false;
\r
165 ok( pass, "Execute a function, Relative" );
\r
168 test("index(Object)", function() {
\r
170 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
171 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
172 var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
173 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
174 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
175 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
176 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
177 ok( inputElements.index(window) == -1, "Check for not found index" );
\r
178 ok( inputElements.index(document) == -1, "Check for not found index" );
\r
181 test("attr(String)", function() {
\r
183 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
184 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
185 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
186 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
187 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
188 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
189 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
190 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
191 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
192 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
193 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
194 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
196 $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
\r
197 ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
\r
200 if ( location.protocol != "file:" ) {
\r
201 test("attr(String) in XML Files", function() {
\r
204 $.get("data/dashboard.xml", function(xml) {
\r
205 ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
\r
206 ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
\r
212 test("attr(String, Function)", function() {
\r
214 ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
\r
215 ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
\r
218 test("attr(Hash)", function() {
\r
221 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
222 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
224 ok( pass, "Set Multiple Attributes" );
\r
227 test("attr(String, Object)", function() {
\r
229 var div = $("div");
\r
230 div.attr("foo", "bar");
\r
232 for ( var i = 0; i < div.size(); i++ ) {
\r
233 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
235 ok( pass, "Set Attribute" );
\r
237 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
\r
239 $("#name").attr('name', 'something');
\r
240 ok( $("#name").attr('name') == 'something', 'Set name attribute' );
\r
241 $("#check2").attr('checked', true);
\r
242 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
243 $("#check2").attr('checked', false);
\r
244 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
245 $("#text1").attr('readonly', true);
\r
246 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
\r
247 $("#text1").attr('readonly', false);
\r
248 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
\r
251 if ( location.protocol != "file:" ) {
\r
252 test("attr(String, Object)x", function() {
\r
255 $.get('data/dashboard.xml', function(xml) {
\r
257 $('tab', xml).each(function() {
\r
258 titles.push($(this).attr('title'));
\r
260 ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
\r
261 ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
\r
267 test("css(String|Hash)", function() {
\r
270 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
272 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
273 $('#foo').css({display: 'none'});
\r
274 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
275 $('#foo').css({display: 'block'});
\r
276 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
278 $('#floatTest').css({styleFloat: 'right'});
\r
279 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
280 $('#floatTest').css({cssFloat: 'left'});
\r
281 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
282 $('#floatTest').css({'float': 'right'});
\r
283 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
\r
284 $('#floatTest').css({'font-size': '30px'});
\r
285 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
287 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
288 $('#foo').css({opacity: n});
\r
289 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
290 $('#foo').css({opacity: parseFloat(n)});
\r
291 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
293 $('#foo').css({opacity: ''});
\r
294 ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
\r
297 test("css(String, Object)", function() {
\r
299 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
300 $('#foo').css('display', 'none');
\r
301 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
302 $('#foo').css('display', 'block');
\r
303 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
305 $('#floatTest').css('styleFloat', 'left');
\r
306 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
307 $('#floatTest').css('cssFloat', 'right');
\r
308 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
309 $('#floatTest').css('float', 'left');
\r
310 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
\r
311 $('#floatTest').css('font-size', '20px');
\r
312 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
314 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
315 $('#foo').css('opacity', n);
\r
316 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
317 $('#foo').css('opacity', parseFloat(n));
\r
318 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
320 $('#foo').css('opacity', '');
\r
321 ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
\r
324 test("text()", function() {
326 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
327 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
330 test("wrap(String|Element)", function() {
\r
332 var defaultText = 'Try them out:'
\r
333 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
334 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
335 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
338 var defaultText = 'Try them out:'
\r
339 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
340 ok( result.is('ol'), 'Check for element wrapping' );
\r
341 ok( result.text() == defaultText, 'Check for element wrapping' );
345 $('#check1').click(function() {
\r
346 var checkbox = this;
\r
347 ok( !checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
348 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
\r
349 ok( !checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
350 // use a fade in to check state after this event handler has finished
\r
351 $("#c1").fadeIn(function() {
\r
352 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
358 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
360 var defaultText = 'Try them out:'
\r
361 var result = $('#first').append('<b>buga</b>');
\r
362 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
363 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
366 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
367 $('#sap').append(document.getElementById('first'));
\r
368 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
371 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
372 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
373 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
376 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
377 $('#sap').append($("#first, #yahoo"));
\r
378 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
381 $("#sap").append( 5 );
\r
382 ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
385 $("#sap").append( " text with spaces " );
\r
386 ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
\r
389 ok( $("#sap").append([]), "Check for appending an empty array." );
\r
390 ok( $("#sap").append(""), "Check for appending an empty string." );
\r
391 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
394 $("#sap").append(document.getElementById('form'));
\r
395 ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910
\r
400 $( $("iframe")[0].contentWindow.document.body ).append("<div>test</div>");
\r
405 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
\r
409 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
411 var defaultText = 'Try them out:'
\r
412 $('<b>buga</b>').appendTo('#first');
\r
413 ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
\r
414 ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
417 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
418 $(document.getElementById('first')).appendTo('#sap');
\r
419 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
422 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
423 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
424 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
427 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
428 $("#first, #yahoo").appendTo('#sap');
\r
429 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
432 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
434 var defaultText = 'Try them out:'
\r
435 var result = $('#first').prepend('<b>buga</b>');
\r
436 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
437 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
440 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
441 $('#sap').prepend(document.getElementById('first'));
\r
442 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
445 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
446 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
447 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
450 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
451 $('#sap').prepend($("#first, #yahoo"));
\r
452 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
455 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
457 var defaultText = 'Try them out:'
\r
458 $('<b>buga</b>').prependTo('#first');
\r
459 ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
460 ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
463 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
464 $(document.getElementById('first')).prependTo('#sap');
\r
465 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
468 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
469 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
470 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
473 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
474 $("#yahoo, #first").prependTo('#sap');
\r
475 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
478 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
480 var expected = 'This is a normal link: bugaYahoo';
\r
481 $('#yahoo').before('<b>buga</b>');
\r
482 ok( expected == $('#en').text(), 'Insert String before' );
\r
485 expected = "This is a normal link: Try them out:Yahoo";
\r
486 $('#yahoo').before(document.getElementById('first'));
\r
487 ok( expected == $('#en').text(), "Insert element before" );
\r
490 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
491 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
492 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
495 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
496 $('#yahoo').before($("#first, #mark"));
\r
497 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
500 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
502 var expected = 'This is a normal link: bugaYahoo';
\r
503 $('<b>buga</b>').insertBefore('#yahoo');
\r
504 ok( expected == $('#en').text(), 'Insert String before' );
\r
507 expected = "This is a normal link: Try them out:Yahoo";
\r
508 $(document.getElementById('first')).insertBefore('#yahoo');
\r
509 ok( expected == $('#en').text(), "Insert element before" );
\r
512 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
513 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
514 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
517 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
518 $("#first, #mark").insertBefore('#yahoo');
\r
519 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
522 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
524 var expected = 'This is a normal link: Yahoobuga';
\r
525 $('#yahoo').after('<b>buga</b>');
\r
526 ok( expected == $('#en').text(), 'Insert String after' );
\r
529 expected = "This is a normal link: YahooTry them out:";
\r
530 $('#yahoo').after(document.getElementById('first'));
\r
531 ok( expected == $('#en').text(), "Insert element after" );
\r
534 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
535 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
536 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
539 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
540 $('#yahoo').after($("#first, #mark"));
\r
541 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
544 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
546 var expected = 'This is a normal link: Yahoobuga';
\r
547 $('<b>buga</b>').insertAfter('#yahoo');
\r
548 ok( expected == $('#en').text(), 'Insert String after' );
\r
551 expected = "This is a normal link: YahooTry them out:";
\r
552 $(document.getElementById('first')).insertAfter('#yahoo');
\r
553 ok( expected == $('#en').text(), "Insert element after" );
\r
556 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
557 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
558 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
561 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
562 $("#mark, #first").insertAfter('#yahoo');
\r
563 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
566 test("end()", function() {
\r
568 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
569 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
571 var x = $('#yahoo');
\r
573 ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
576 test("find(String)", function() {
578 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
581 test("clone()", function() {
\r
583 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
584 var clone = $('#yahoo').clone();
\r
585 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
586 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
589 test("is(String)", function() {
\r
591 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
592 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
593 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
594 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
595 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
596 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
597 ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
598 ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
599 ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
600 ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
601 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
602 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
603 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
604 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
605 ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
606 ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
607 ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
608 ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
609 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
610 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
611 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
612 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
614 // test is() with comma-seperated expressions
\r
615 ok( $('#en').is('[@lang="en"],[@lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
616 ok( $('#en').is('[@lang="de"],[@lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
617 ok( $('#en').is('[@lang="en"] , [@lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
618 ok( $('#en').is('[@lang="de"] , [@lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
621 test("$.extend(Object, Object)", function() {
\r
623 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
624 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
625 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
626 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
627 jQuery.extend(settings, options);
\r
628 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
629 isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
632 test("$.extend(Object, Object, Object, Object)", function() {
\r
634 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
635 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
636 options1 = { xnumber2: 1, xstring2: "x" },
\r
637 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
638 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
639 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
640 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
641 var settings = jQuery.extend({}, defaults, options1, options2);
\r
642 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
643 isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
644 isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
645 isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
648 test("val()", function() {
\r
650 ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
651 ok( !$("#text1").val() == "", "Check for value of input element" );
\r
654 test("val(String)", function() {
\r
656 document.getElementById('text1').value = "bla";
\r
657 ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
658 $("#text1").val('test');
\r
659 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
662 test("html(String)", function() {
\r
664 var div = $("div");
\r
665 div.html("<b>test</b>");
\r
667 for ( var i = 0; i < div.size(); i++ ) {
\r
668 if ( div.get(i).childNodes.length == 0 ) pass = false;
\r
670 ok( pass, "Set HTML" );
672 $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>').evalScripts();
\r
675 test("filter()", function() {
\r
677 isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
678 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
679 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
680 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
683 test("not()", function() {
\r
685 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
\r
686 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
687 isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
\r
690 test("siblings([String])", function() {
\r
692 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
693 isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
694 isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
695 isSet( $("#foo").siblings("form, b").get(), q("form", "floatTest"), "Check for multiple filters" );
\r
698 test("children([String])", function() {
\r
700 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
701 isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
702 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
705 test("parent[s]([String])", function() {
\r
707 ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
\r
708 ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
\r
709 ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
\r
710 ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
\r
712 ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
\r
713 ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
\r
714 ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
\r
715 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
718 test("next/prev([String])", function() {
\r
720 ok( $("#ap").next()[0].id == "foo", "Simple next check" );
\r
721 ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
\r
722 ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
\r
723 ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
\r
725 ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
\r
726 ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
\r
727 ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
\r
728 ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
\r
731 test("show()", function() {
\r
733 var pass = true, div = $("div");
\r
734 div.show().each(function(){
\r
735 if ( this.style.display == "none" ) pass = false;
\r
737 ok( pass, "Show" );
\r
740 test("addClass(String)", function() {
742 var div = $("div");
\r
743 div.addClass("test");
\r
745 for ( var i = 0; i < div.size(); i++ ) {
\r
746 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
748 ok( pass, "Add Class" );
\r
751 test("removeClass(String) - simple", function() {
\r
753 var div = $("div").addClass("test").removeClass("test"),
\r
755 for ( var i = 0; i < div.size(); i++ ) {
\r
756 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
758 ok( pass, "Remove Class" );
761 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
762 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
764 for ( var i = 0; i < div.size(); i++ ) {
\r
765 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
767 ok( pass, "Remove multiple classes" );
\r
770 test("toggleClass(String)", function() {
\r
772 var e = $("#firstp");
\r
773 ok( !e.is(".test"), "Assert class not present" );
\r
774 e.toggleClass("test");
\r
775 ok( e.is(".test"), "Assert class present" );
\r
776 e.toggleClass("test");
\r
777 ok( !e.is(".test"), "Assert class not present" );
\r
780 test("removeAttr(String", function() {
782 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
\r
785 test("text(String)", function() {
\r
787 ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
790 test("$.each(Object,Function)", function() {
\r
792 $.each( [0,1,2], function(i, n){
\r
793 ok( i == n, "Check array iteration" );
\r
796 $.each( [5,6,7], function(i, n){
\r
797 ok( i == n - 5, "Check array iteration" );
\r
800 $.each( { name: "name", lang: "lang" }, function(i, n){
\r
801 ok( i == n, "Check object iteration" );
\r
805 test("$.prop", function() {
\r
807 var handle = function() { return this.id };
\r
808 ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
\r
809 ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
\r
812 test("$.className", function() {
\r
814 var x = $("<p>Hi</p>")[0];
\r
815 var c = $.className;
\r
817 ok( x.className == "hi", "Check single added class" );
\r
818 c.add(x, "foo bar");
\r
819 ok( x.className == "hi foo bar", "Check more added classes" );
\r
821 ok( x.className == "", "Remove all classes" );
\r
822 c.add(x, "hi foo bar");
\r
823 c.remove(x, "foo");
\r
824 ok( x.className == "hi bar", "Check removal of one class" );
\r
825 ok( c.has(x, "hi"), "Check has1" );
\r
826 ok( c.has(x, "bar"), "Check has2" );
\r
829 test("remove()", function() {
831 $("#ap").children().remove();
\r
832 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
833 ok( $("#ap").children().length == 0, "Check remove" );
\r
836 $("#ap").children().remove("a");
\r
837 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
838 ok( $("#ap").children().length == 1, "Check filtered remove" );
\r
841 test("empty()", function() {
843 ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
\r
844 ok( $("#ap").children().length == 4, "Check elements are not removed" );
\r
847 test("eq(), gt(), lt(), contains()", function() {
849 ok( $("#ap a").eq(1)[0].id == "groups", "eq()" );
\r
850 isSet( $("#ap a").gt(0).get(), q("groups", "anchor1", "mark"), "gt()" );
\r
851 isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" );
\r
852 isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );
\r