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() {
\r
15 var main = $("#main");
\r
16 isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
\r
18 // make sure this is handled
\r
22 test("isFunction", function() {
\r
25 // Make sure that false values return false
\r
26 ok( !jQuery.isFunction(), "No Value" );
\r
27 ok( !jQuery.isFunction( null ), "null Value" );
\r
28 ok( !jQuery.isFunction( undefined ), "undefined Value" );
\r
29 ok( !jQuery.isFunction( "" ), "Empty String Value" );
\r
30 ok( !jQuery.isFunction( 0 ), "0 Value" );
\r
33 // Safari uses "(Internal Function)"
\r
34 ok( jQuery.isFunction(String), "String Function" );
\r
35 ok( jQuery.isFunction(Array), "Array Function" );
\r
36 ok( jQuery.isFunction(Object), "Object Function" );
\r
37 ok( jQuery.isFunction(Function), "Function Function" );
\r
39 // When stringified, this could be misinterpreted
\r
40 var mystr = "function";
\r
41 ok( !jQuery.isFunction(mystr), "Function String" );
\r
43 // When stringified, this could be misinterpreted
\r
44 var myarr = [ "function" ];
\r
45 ok( !jQuery.isFunction(myarr), "Function Array" );
\r
47 // When stringified, this could be misinterpreted
\r
48 var myfunction = { "function": "test" };
\r
49 ok( !jQuery.isFunction(myfunction), "Function Object" );
\r
51 // Make sure normal functions still work
\r
52 var fn = function(){};
\r
53 ok( jQuery.isFunction(fn), "Normal Function" );
\r
55 var obj = document.createElement("object");
\r
57 // Firefox says this is a function
\r
58 ok( !jQuery.isFunction(obj), "Object Element" );
\r
60 // IE says this is an object
\r
61 ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
\r
63 var nodes = document.body.childNodes;
\r
65 // Safari says this is a function
\r
66 ok( !jQuery.isFunction(nodes), "childNodes Property" );
\r
68 var first = document.body.firstChild;
\r
70 // Normal elements are reported ok everywhere
\r
71 ok( !jQuery.isFunction(first), "A normal DOM Element" );
\r
73 var input = document.createElement("input");
\r
74 input.type = "text";
\r
75 document.body.appendChild( input );
\r
77 // IE says this is an object
\r
78 ok( jQuery.isFunction(input.focus), "A default function property" );
\r
80 document.body.removeChild( input );
\r
82 var a = document.createElement("a");
\r
83 a.href = "some-function";
\r
84 document.body.appendChild( a );
\r
86 // This serializes with the word 'function' in it
\r
87 ok( !jQuery.isFunction(a), "Anchor Element" );
\r
89 document.body.removeChild( a );
\r
91 // Recursive function calls have lengths and array-like properties
\r
92 function callme(callback){
\r
93 function fn(response){
\r
97 ok( jQuery.isFunction(fn), "Recursive Function Call" );
\r
99 fn({ some: "data" });
\r
103 callme(function(){});
\r
107 test("length", function() {
\r
108 ok( $("div").length == 2, "Get Number of Elements Found" );
\r
111 test("size()", function() {
\r
112 ok( $("div").size() == 2, "Get Number of Elements Found" );
\r
115 test("get()", function() {
\r
116 isSet( $("div").get(), q("main","foo"), "Get All Elements" );
\r
119 test("get(Number)", function() {
\r
120 ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
\r
123 test("add(String|Element|Array)", function() {
\r
124 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
125 isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
126 ok( $([]).add($("#form")[0].elements).length > 13, "Check elements from array" );
\r
128 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
\r
129 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
130 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
132 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
133 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
134 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
137 test("each(Function)", function() {
\r
139 var div = $("div");
\r
140 div.each(function(){this.foo = 'zoo';});
\r
142 for ( var i = 0; i < div.size(); i++ ) {
\r
143 if ( div.get(i).foo != "zoo" ) pass = false;
\r
145 ok( pass, "Execute a function, Relative" );
\r
148 test("index(Object)", function() {
\r
150 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
151 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
152 var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
153 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
154 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
155 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
156 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
157 ok( inputElements.index(window) == -1, "Check for not found index" );
\r
158 ok( inputElements.index(document) == -1, "Check for not found index" );
\r
161 test("attr(String)", function() {
\r
163 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
164 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
165 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
166 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
167 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
168 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
169 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
170 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
171 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
172 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
173 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
174 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
176 $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
\r
177 ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
\r
180 $.get("data/dashboard.xml", function(xml) {
\r
181 ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
\r
182 ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
\r
187 test("attr(String, Function)", function() {
\r
189 ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
\r
190 ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
\r
193 test("attr(Hash)", function() {
\r
196 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
197 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
199 ok( pass, "Set Multiple Attributes" );
\r
202 test("attr(String, Object)", function() {
\r
204 var div = $("div");
\r
205 div.attr("foo", "bar");
\r
207 for ( var i = 0; i < div.size(); i++ ) {
\r
208 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
210 ok( pass, "Set Attribute" );
\r
212 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
\r
214 $("#name").attr('name', 'something');
\r
215 ok( $("#name").attr('name') == 'something', 'Set name attribute' );
\r
216 $("#check2").attr('checked', true);
\r
217 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
218 $("#check2").attr('checked', false);
\r
219 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
220 $("#text1").attr('readonly', true);
\r
221 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
\r
222 $("#text1").attr('readonly', false);
\r
223 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
\r
226 if ( location.protocol != "file:" ) {
\r
227 test("attr(String, Object)x", function() {
\r
230 $.get('data/dashboard.xml', function(xml) {
\r
232 $('tab', xml).each(function() {
\r
233 titles.push($(this).attr('title'));
\r
235 ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
\r
236 ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
\r
242 test("css(String|Hash)", function() {
\r
245 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
247 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
248 $('#foo').css({display: 'none'});
\r
249 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
250 $('#foo').css({display: 'block'});
\r
251 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
253 $('#floatTest').css({styleFloat: 'right'});
\r
254 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
255 $('#floatTest').css({cssFloat: 'left'});
\r
256 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
257 $('#floatTest').css({'float': 'right'});
\r
258 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
\r
259 $('#floatTest').css({'font-size': '30px'});
\r
260 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
263 test("css(String, Object)", function() {
\r
265 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
266 $('#foo').css('display', 'none');
\r
267 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
268 $('#foo').css('display', 'block');
\r
269 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
271 $('#floatTest').css('styleFloat', 'left');
\r
272 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
273 $('#floatTest').css('cssFloat', 'right');
\r
274 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
275 $('#floatTest').css('float', 'left');
\r
276 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
\r
277 $('#floatTest').css('font-size', '20px');
\r
278 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
281 test("text()", function() {
\r
282 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
283 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
286 test("wrap(String|Element)", function() {
\r
288 var defaultText = 'Try them out:'
\r
289 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
290 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
291 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
294 var defaultText = 'Try them out:'
\r
295 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
296 ok( result.is('ol'), 'Check for element wrapping' );
\r
297 ok( result.text() == defaultText, 'Check for element wrapping' );
\r
300 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
302 var defaultText = 'Try them out:'
\r
303 var result = $('#first').append('<b>buga</b>');
\r
304 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
305 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
308 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
309 $('#sap').append(document.getElementById('first'));
\r
310 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
313 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
314 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
315 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
318 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
319 $('#sap').append($("#first, #yahoo"));
\r
320 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
323 $("#sap").append( 5 );
\r
324 ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
327 $("#sap").append( " text with spaces " );
\r
328 ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
\r
331 ok( $("#sap").append([]), "Check for appending an empty array." );
\r
332 ok( $("#sap").append(""), "Check for appending an empty string." );
\r
333 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
336 $("#sap").append(document.getElementById('form'));
\r
337 ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910
\r
341 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
343 var defaultText = 'Try them out:'
\r
344 $('<b>buga</b>').appendTo('#first');
\r
345 ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
\r
346 ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
349 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
350 $(document.getElementById('first')).appendTo('#sap');
\r
351 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
354 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
355 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
356 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
359 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
360 $("#first, #yahoo").appendTo('#sap');
\r
361 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
364 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
366 var defaultText = 'Try them out:'
\r
367 var result = $('#first').prepend('<b>buga</b>');
\r
368 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
369 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
372 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
373 $('#sap').prepend(document.getElementById('first'));
\r
374 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
377 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
378 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
379 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
382 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
383 $('#sap').prepend($("#first, #yahoo"));
\r
384 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
387 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
389 var defaultText = 'Try them out:'
\r
390 $('<b>buga</b>').prependTo('#first');
\r
391 ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
392 ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
395 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
396 $(document.getElementById('first')).prependTo('#sap');
\r
397 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
400 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
401 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
402 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
405 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
406 $("#yahoo, #first").prependTo('#sap');
\r
407 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
410 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
412 var expected = 'This is a normal link: bugaYahoo';
\r
413 $('#yahoo').before('<b>buga</b>');
\r
414 ok( expected == $('#en').text(), 'Insert String before' );
\r
417 expected = "This is a normal link: Try them out:Yahoo";
\r
418 $('#yahoo').before(document.getElementById('first'));
\r
419 ok( expected == $('#en').text(), "Insert element before" );
\r
422 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
423 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
424 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
427 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
428 $('#yahoo').before($("#first, #mark"));
\r
429 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
432 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
434 var expected = 'This is a normal link: bugaYahoo';
\r
435 $('<b>buga</b>').insertBefore('#yahoo');
\r
436 ok( expected == $('#en').text(), 'Insert String before' );
\r
439 expected = "This is a normal link: Try them out:Yahoo";
\r
440 $(document.getElementById('first')).insertBefore('#yahoo');
\r
441 ok( expected == $('#en').text(), "Insert element before" );
\r
444 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
445 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
446 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
449 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
450 $("#first, #mark").insertBefore('#yahoo');
\r
451 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
454 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
456 var expected = 'This is a normal link: Yahoobuga';
\r
457 $('#yahoo').after('<b>buga</b>');
\r
458 ok( expected == $('#en').text(), 'Insert String after' );
\r
461 expected = "This is a normal link: YahooTry them out:";
\r
462 $('#yahoo').after(document.getElementById('first'));
\r
463 ok( expected == $('#en').text(), "Insert element after" );
\r
466 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
467 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
468 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
471 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
472 $('#yahoo').after($("#first, #mark"));
\r
473 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
476 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
478 var expected = 'This is a normal link: Yahoobuga';
\r
479 $('<b>buga</b>').insertAfter('#yahoo');
\r
480 ok( expected == $('#en').text(), 'Insert String after' );
\r
483 expected = "This is a normal link: YahooTry them out:";
\r
484 $(document.getElementById('first')).insertAfter('#yahoo');
\r
485 ok( expected == $('#en').text(), "Insert element after" );
\r
488 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
489 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
490 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
493 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
494 $("#mark, #first").insertAfter('#yahoo');
\r
495 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
498 test("end()", function() {
\r
500 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
501 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
503 var x = $('#yahoo');
\r
505 ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
508 test("find(String)", function() {
\r
509 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
512 test("clone()", function() {
\r
514 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
515 var clone = $('#yahoo').clone();
\r
516 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
517 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
520 test("is(String)", function() {
\r
522 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
523 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
524 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
525 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
526 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
527 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
528 ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
529 ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
530 ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
531 ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
532 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
533 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
534 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
535 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
536 ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
537 ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
538 ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
539 ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
540 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
541 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
542 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
543 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
545 // test is() with comma-seperated expressions
\r
546 ok( $('#en').is('[@lang="en"],[@lang="de"]'), 'Check for lang attribute: Expecte en or de' );
\r
547 ok( $('#en').is('[@lang="de"],[@lang="en"]'), 'Check for lang attribute: Expecte en or de' );
\r
548 ok( $('#en').is('[@lang="en"] , [@lang="de"]'), 'Check for lang attribute: Expecte en or de' );
\r
549 ok( $('#en').is('[@lang="de"] , [@lang="en"]'), 'Check for lang attribute: Expecte en or de' );
\r
552 test("$.extend(Object, Object)", function() {
\r
554 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
555 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
556 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
557 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
558 jQuery.extend(settings, options);
\r
559 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
560 isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
563 test("$.extend(Object, Object, Object, Object)", function() {
\r
565 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
566 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
567 options1 = { xnumber2: 1, xstring2: "x" },
\r
568 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
569 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
570 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
571 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
572 var settings = jQuery.extend({}, defaults, options1, options2);
\r
573 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
574 isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
575 isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
576 isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
579 test("val()", function() {
\r
581 ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
582 ok( !$("#text1").val() == "", "Check for value of input element" );
\r
585 test("val(String)", function() {
\r
587 document.getElementById('text1').value = "bla";
\r
588 ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
589 $("#text1").val('test');
\r
590 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
593 test("html(String)", function() {
\r
595 var div = $("div");
\r
596 div.html("<b>test</b>");
\r
598 for ( var i = 0; i < div.size(); i++ ) {
\r
599 if ( div.get(i).childNodes.length == 0 ) pass = false;
\r
601 ok( pass, "Set HTML" );
\r
604 test("filter()", function() {
\r
606 isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
607 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
608 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
609 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
612 test("not()", function() {
\r
614 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
\r
615 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
616 isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
\r
620 test("siblings([String])", function() {
\r
622 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
623 isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
624 isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
625 isSet( $("#foo").siblings("form, b").get(), q("form", "floatTest"), "Check for multiple filters" );
\r
628 test("children([String])", function() {
\r
630 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
631 isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
632 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
635 test("parent[s]([String])", function() {
\r
637 ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
\r
638 ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
\r
639 ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
\r
640 ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
\r
642 ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
\r
643 ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
\r
644 ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
\r
645 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
648 test("next/prev([String])", function() {
\r
650 ok( $("#ap").next()[0].id == "foo", "Simple next check" );
\r
651 ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
\r
652 ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
\r
653 ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
\r
655 ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
\r
656 ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
\r
657 ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
\r
658 ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
\r
661 test("show()", function() {
\r
663 var pass = true, div = $("div");
\r
664 div.show().each(function(){
\r
665 if ( this.style.display == "none" ) pass = false;
\r
667 ok( pass, "Show" );
\r
670 test("addClass(String)", function() {
\r
671 var div = $("div");
\r
672 div.addClass("test");
\r
674 for ( var i = 0; i < div.size(); i++ ) {
\r
675 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
677 ok( pass, "Add Class" );
\r
680 test("removeClass(String) - simple", function() {
\r
682 var div = $("div").addClass("test").removeClass("test"),
\r
684 for ( var i = 0; i < div.size(); i++ ) {
\r
685 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
687 ok( pass, "Remove Class" );
\r
690 test("removeClass(String) - add three classes and remove again", function() {
\r
692 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
693 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
695 for ( var i = 0; i < div.size(); i++ ) {
\r
696 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
698 ok( pass, "Remove multiple classes" );
\r
701 test("toggleClass(String)", function() {
\r
703 var e = $("#firstp");
\r
704 ok( !e.is(".test"), "Assert class not present" );
\r
705 e.toggleClass("test");
\r
706 ok( e.is(".test"), "Assert class present" );
\r
707 e.toggleClass("test");
\r
708 ok( !e.is(".test"), "Assert class not present" );
\r
711 test("removeAttr(String", function() {
\r
712 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
\r
715 test("text(String)", function() {
\r
717 ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
720 test("$.each(Object,Function)", function() {
\r
722 $.each( [0,1,2], function(i, n){
\r
723 ok( i == n, "Check array iteration" );
\r
726 $.each( [5,6,7], function(i, n){
\r
727 ok( i == n - 5, "Check array iteration" );
\r
730 $.each( { name: "name", lang: "lang" }, function(i, n){
\r
731 ok( i == n, "Check object iteration" );
\r
735 test("$.prop", function() {
\r
737 var handle = function() { return this.id };
\r
738 ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
\r
739 ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
\r
742 test("$.className", function() {
\r
744 var x = $("<p>Hi</p>")[0];
\r
745 var c = $.className;
\r
747 ok( x.className == "hi", "Check single added class" );
\r
748 c.add(x, "foo bar");
\r
749 ok( x.className == "hi foo bar", "Check more added classes" );
\r
751 ok( x.className == "", "Remove all classes" );
\r
752 c.add(x, "hi foo bar");
\r
753 c.remove(x, "foo");
\r
754 ok( x.className == "hi bar", "Check removal of one class" );
\r
755 ok( c.has(x, "hi"), "Check has1" );
\r
756 ok( c.has(x, "bar"), "Check has2" );
\r
759 test("remove()", function() {
\r
760 $("#ap").children().remove();
\r
761 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
762 ok( $("#ap").children().length == 0, "Check remove" );
\r
765 $("#ap").children().remove("a");
\r
766 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
767 ok( $("#ap").children().length == 1, "Check filtered remove" );
\r
770 test("empty()", function() {
\r
771 ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
\r
772 ok( $("#ap").children().length == 4, "Check elements are not removed" );
\r
775 test("eq(), gt(), lt(), contains()", function() {
\r
776 ok( $("#ap a").eq(1)[0].id == "groups", "eq()" );
\r
777 isSet( $("#ap a").gt(0).get(), q("groups", "anchor1", "mark"), "gt()" );
\r
778 isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" );
\r
779 isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );
\r
782 test("click() context", function() {
\r
783 $('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
\r
784 var close = $('spanx', this); // same with $(this).find('span');
\r
785 ok( close.length == 0, "Element does not exist, length must be zero" );
\r
786 ok( !close[0], "Element does not exist, direct access to element must return undefined" );
\r
787 //console.log( close[0]); // it's the <a> and not a <span> element
\r