Testsuite 2.0
[jquery.git] / src / jquery / coreTest.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("length", function() {
15         ok( $("div").length == 2, "Get Number of Elements Found" );
16 });
17
18 test("size()", function() {
19         ok( $("div").size() == 2, "Get Number of Elements Found" );
20 });
21
22 test("get()", function() {
23         isSet( $("div").get(), q("main","foo"), "Get All Elements" );
24 });
25
26 test("get(Number)", function() {
27         ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
28 });
29
30 test("each(Function)", function() {
31         expect(1);
32         var div = $("div");
33         div.each(function(){this.foo = 'zoo';});
34         var pass = true;
35         for ( var i = 0; i < div.size(); i++ ) {
36           if ( div.get(i).foo != "zoo" ) pass = false;
37         }
38         ok( pass, "Execute a function, Relative" );
39 });
40
41 test("index(Object)", function() {
42         expect(8);
43         ok( $([window, document]).index(window) == 0, "Check for index of elements" );
44         ok( $([window, document]).index(document) == 1, "Check for index of elements" );
45         var inputElements = $('#radio1,#radio2,#check1,#check2');
46         ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
47         ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
48         ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
49         ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
50         ok( inputElements.index(window) == -1, "Check for not found index" );
51         ok( inputElements.index(document) == -1, "Check for not found index" );
52 });
53
54 test("attr(String)", function() {
55         expect(12);
56         ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
57         ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
58         ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
59         ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
60         ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
61         ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
62         ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
63         ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
64         ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
65         ok( $('#name').attr('name') == "name", 'Check for name attribute' );
66         ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
67         ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
68 });
69
70 test("attr(Hash)", function() {
71         expect(1);
72         var pass = true;
73         $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
74           if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
75         });
76         ok( pass, "Set Multiple Attributes" );
77 });
78
79 test("attr(String, Object)", function() {
80         expect(6);
81         var div = $("div");
82         div.attr("foo", "bar");
83         var pass = true;
84         for ( var i = 0; i < div.size(); i++ ) {
85           if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
86         }
87         ok( pass, "Set Attribute" );
88         
89         $("#name").attr('name', 'something');
90         ok( $("#name").name() == 'something', 'Set name attribute' );
91         $("#check2").attr('checked', true);
92         ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
93         $("#check2").attr('checked', false);
94         ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
95         $("#text1").attr('readonly', true);
96         ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
97         $("#text1").attr('readonly', false);
98         ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
99 });
100
101 test("attr(String, Object)x", function() {
102         expect(2);
103         stop();
104         $.get('data/dashboard.xml', function(xml) { 
105           var titles = [];
106           $('tab', xml).each(function() {
107             titles.push($(this).attr('title'));
108           });
109           ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
110           ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
111           start();
112         });
113 });
114
115 test("css(String|Hash)", function() {
116         expect(8);
117         
118         ok( $('#main').css("display") == 'none', 'Check for css property "display"');
119         
120         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
121         $('#foo').css({display: 'none'});
122         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
123         $('#foo').css({display: 'block'});
124         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
125         
126         $('#floatTest').css({styleFloat: 'right'});
127         ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
128         $('#floatTest').css({cssFloat: 'left'});
129         ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
130         $('#floatTest').css({'float': 'right'});
131         ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
132         $('#floatTest').css({'font-size': '30px'});
133         ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
134 });
135
136 test("css(String, Object)", function() {
137         expect(7);
138         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
139         $('#foo').css('display', 'none');
140         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
141         $('#foo').css('display', 'block');
142         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
143         
144         $('#floatTest').css('styleFloat', 'left');
145         ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
146         $('#floatTest').css('cssFloat', 'right');
147         ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
148         $('#floatTest').css('float', 'left');
149         ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
150         $('#floatTest').css('font-size', '20px');
151         ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
152 });
153
154 test("text()", function() {
155         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
156         ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
157 });
158
159 test("wrap(String|Element)", function() {
160         expect(4);
161         var defaultText = 'Try them out:'
162         var result = $('#first').wrap('<div class="red"><span></span></div>').text();
163         ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
164         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
165
166         reset();
167         var defaultText = 'Try them out:'
168         var result = $('#first').wrap(document.getElementById('empty')).parent();
169         ok( result.is('ol'), 'Check for element wrapping' );
170         ok( result.text() == defaultText, 'Check for element wrapping' );
171 });
172
173 test("append(String|Element|Array&lt;Element&gt;)", function() {
174         expect(4);
175         var defaultText = 'Try them out:'
176         var result = $('#first').append('<b>buga</b>');
177         ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
178         ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
179         
180         reset();
181         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
182         $('#sap').append(document.getElementById('first'));
183         ok( expected == $('#sap').text(), "Check for appending of element" );
184         
185         reset();
186         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
187         $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
188         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
189 });
190
191 test("prepend(String|Element|Array&lt;Element&gt;)", function() {
192         expect(4);
193         var defaultText = 'Try them out:'
194         var result = $('#first').prepend('<b>buga</b>');
195         ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
196         ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
197         
198         reset();
199         expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
200         $('#sap').prepend(document.getElementById('first'));
201         ok( expected == $('#sap').text(), "Check for prepending of element" );
202
203         reset();
204         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
205         $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
206         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
207 });
208
209 test("before(String|Element|Array&lt;Element&gt;)", function() {
210         expect(3);
211         var expected = 'This is a normal link: bugaYahoo';
212         $('#yahoo').before('<b>buga</b>');
213         ok( expected == $('#en').text(), 'Insert String before' );
214         
215         reset();
216         expected = "This is a normal link: Try them out:Yahoo";
217         $('#yahoo').before(document.getElementById('first'));
218         ok( expected == $('#en').text(), "Insert element before" );
219         
220         reset();
221         expected = "This is a normal link: Try them out:diveintomarkYahoo";
222         $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
223         ok( expected == $('#en').text(), "Insert array of elements before" );
224 });
225
226 test("after(String|Element|Array&lt;Element&gt;)", function() {
227         expect(3);
228         var expected = 'This is a normal link: Yahoobuga';
229         $('#yahoo').after('<b>buga</b>');
230         ok( expected == $('#en').text(), 'Insert String after' );
231         
232         reset();
233         expected = "This is a normal link: YahooTry them out:";
234         $('#yahoo').after(document.getElementById('first'));
235         ok( expected == $('#en').text(), "Insert element after" );
236
237         reset();
238         expected = "This is a normal link: YahooTry them out:diveintomark";
239         $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
240         ok( expected == $('#en').text(), "Insert array of elements after" );
241 });
242
243 test("end()", function() {
244         expect(2);
245         ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
246         ok( $('#yahoo').end(), 'Check for end with nothing to end' );
247 });
248
249 test("find(String)", function() {
250         ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
251 });
252
253 test("clone()", function() {
254         expect(3);
255         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
256         var clone = $('#yahoo').clone();
257         ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
258         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
259 });
260
261 test("filter(String)", function() {
262         isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
263 });
264
265 test("filter(String) - execute callback in fitting context", function() {
266         expect(1);
267         $("input").filter(":checked",function(i){ 
268                 ok( this == q("radio2", "check1")[i], "Filter elements, context" );
269         });
270 });
271
272 test("filter(String) - execute callback in not-fitting context", function() {
273         expect(1);
274         $("#main > p#ap > a").filter("#foobar",function(){},function(i){
275                 ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
276         });
277 });
278
279 test("not(String)", function() {
280         ok($("#main > p#ap > a").not("#google").length == 2, ".not")
281 });
282
283 test("is(String)", function() {
284         expect(22);
285         ok( $('#form').is('form'), 'Check for element: A form must be a form' );
286         ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
287         ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
288         ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
289         ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
290         ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
291         ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
292         ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
293         ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
294         ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
295         ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
296         ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
297         ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
298         ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
299         ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
300         ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
301         ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
302         ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
303         ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
304         ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
305         ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
306         ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
307 });
308
309 test("$.extend(Object, Object)", function() {
310         expect(2);
311         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
312                 options =     { xnumber2: 1, xstring2: "x", xxx: "newstring" },
313                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
314                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
315         jQuery.extend(settings, options);
316         isSet( settings, merged, "Check if extended: settings must be extended" );
317         isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
318 });
319
320 test("expressions - element", function() {
321         expect(5);
322         ok( $("*").size() >= 30, "Select all" );
323         t( "Element Selector", "div", ["main","foo"] );
324         t( "Element Selector", "body", ["body"] );
325         t( "Element Selector", "html", ["html"] );
326         t( "Parent Element", "div div", ["foo"] );
327 });
328
329 test("expressions - id", function() {
330         expect(5);
331         t( "ID Selector", "#body", ["body"] );
332         t( "ID Selector w/ Element", "body#body", ["body"] );
333         t( "ID Selector w/ Element", "ul#first", [] );
334         
335         t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"]  );
336         t( "All Children of ID with no children", "#firstUL/*", []  );
337 });
338
339 test("expressions - class", function() {
340         expect(4);
341         t( "Class Selector", ".blog", ["mark","simon"] );
342         t( "Class Selector", ".blog.link", ["simon"] );
343         t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
344         t( "Parent Class Selector", "p .blog", ["mark","simon"] );
345 });
346
347 test("expressions - multiple", function() {
348         expect(4);
349         t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
350         t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
351         t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
352         t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
353 });
354
355 test("expressions - child and adjacent", function() {
356         expect(14);
357         t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
358         t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
359         t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
360         t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
361         t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
362         t( "All Children", "code > *", ["anchor1","anchor2"] );
363         t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
364         t( "Adjacent", "a + a", ["groups"] );
365         t( "Adjacent", "a +a", ["groups"] );
366         t( "Adjacent", "a+ a", ["groups"] );
367         t( "Adjacent", "a+a", ["groups"] );
368         t( "Adjacent", "p + p", ["ap","en","sap"] );
369         t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
370         t( "First Child", "p:first-child", ["firstp","sndp"] );
371 });
372
373 test("expressions - attributes", function() {
374         expect(16);
375         t( "Attribute Exists", "a[@title]", ["google"] );
376         t( "Attribute Exists", "*[@title]", ["google"] );
377         t( "Attribute Exists", "[@title]", ["google"] );
378         
379         t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
380         t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
381         t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
382         t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
383         t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
384         t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
385         
386         t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
387         t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
388         t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
389         
390         t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
391         
392         t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
393         t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
394         t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
395 });
396
397 test("expressions - pseudo (:) selctors", function() {
398         expect(30);
399         t( "First Child", "p:first-child", ["firstp","sndp"] );
400         t( "Last Child", "p:last-child", ["sap"] );
401         t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
402         t( "Empty", "ul:empty", ["firstUL"] );
403         t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
404         t( "Disabled UI Element", "input:disabled", ["text2"] );
405         t( "Checked UI Element", "input:checked", ["radio2","check1"] );
406         t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
407         t( "Text Contains", "a:contains('Google')", ["google","groups"] );
408         t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
409         t( "Element Preceded By", "p ~ div", ["foo"] );
410         t( "Not", "a.blog:not(.link)", ["mark"] );
411         
412         t( "nth Element", "p:nth(1)", ["ap"] );
413         t( "First Element", "p:first", ["firstp"] );
414         t( "Last Element", "p:last", ["first"] );
415         t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
416         t( "Odd Elements", "p:odd", ["ap","en","first"] );
417         t( "Position Equals", "p:eq(1)", ["ap"] );
418         t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
419         t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
420         t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
421         t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
422         t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
423         
424         t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
425         t( "Form element :radio", ":radio", ["radio1", "radio2"] );
426         t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
427         t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
428         t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
429         t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
430         t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
431 });
432
433 test("expressions - basic xpath", function() {
434         expect(14);
435         ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
436         t( "All Div Elements", "//div", ["main","foo"] );
437         t( "Absolute Path", "/html/body", ["body"] );
438         t( "Absolute Path w/ *", "/* /body", ["body"] );
439         t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
440         t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
441         t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
442         t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
443         t( "Attribute Exists", "//a[@title]", ["google"] );
444         t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
445         t( "Parent Axis", "//p/..", ["main","foo"] );
446         t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
447         t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
448         t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
449 });
450
451 test("val()", function() {
452         expect(2);
453         ok( $("#text1").val() == "Test", "Check for value of input element" );
454         ok( !$("#text1").val() == "", "Check for value of input element" );
455 });
456
457 test("val(String)", function() {
458         expect(2);
459         document.getElementById('text1').value = "bla";
460         ok( $("#text1").val() == "bla", "Check for modified value of input element" );
461         $("#text1").val('test');
462         ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
463 });
464
465 test("html(String)", function() {
466         expect(1);
467         var div = $("div");
468         div.html("<b>test</b>");
469         var pass = true;
470         for ( var i = 0; i < div.size(); i++ ) {
471           if ( div.get(i).childNodes.length == 0 ) pass = false;
472         }
473         ok( pass, "Set HTML" );
474 });
475
476 test("id()", function() {
477         expect(3);
478         ok( $(document.getElementById('main')).id() == "main", "Check for id" );
479         ok( $("#foo").id() == "foo", "Check for id" );
480         ok( !$("head").id(), "Check for id" );
481 });
482
483 test("title()", function() {
484         expect(2);
485         ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
486         ok( !$("#yahoo").title(), "Check for title" );
487 });
488
489 test("name()", function() {
490         expect(3);
491         ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
492         ok( $("#hidden1").name() == "hidden", "Check for name" );
493         ok( !$("#area1").name(), "Check for name" );
494 });
495
496
497 test("siblings([String])", function() {
498         expect(3);
499         isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
500         isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 
501         isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
502 });
503
504 test("children([String])", function() {
505         expect(2);
506         isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
507         isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
508 });
509
510
511 test("show()", function() {
512         expect(1);
513         var pass = true, div = $("div");
514         div.show().each(function(){
515           if ( this.style.display == "none" ) pass = false;
516         });
517         ok( pass, "Show" );
518 });
519
520 test("addClass(String)", function() {
521         var div = $("div");
522         div.addClass("test");
523         var pass = true;
524         for ( var i = 0; i < div.size(); i++ ) {
525          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
526         }
527         ok( pass, "Add Class" );
528 });
529
530 test("removeClass(String) - simple", function() {
531         expect(1);
532         var div = $("div").addClass("test").removeClass("test"),
533                 pass = true;
534         for ( var i = 0; i < div.size(); i++ ) {
535                 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
536         }
537         ok( pass, "Remove Class" );
538 });
539
540 test("removeClass(String) - add three classes and remove again", function() {
541         expect(1);
542         var div = $("div").addClass("test").addClass("foo").addClass("bar");
543         div.removeClass("test").removeClass("bar").removeClass("foo");
544         var pass = true;
545         for ( var i = 0; i < div.size(); i++ ) {
546          if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
547         }
548         ok( pass, "Remove multiple classes" );
549 });