Changeset 5684 for trunk/jquery/test
- Timestamp:
- 05/24/08 18:11:55 (8 months ago)
- Files:
-
- 1 modified
-
trunk/jquery/test/unit/core.js (modified) (66 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/test/unit/core.js
r5602 r5684 14 14 test("$()", function() { 15 15 expect(8); 16 16 17 17 var main = $("#main"); 18 18 isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); 19 19 20 20 /* 21 21 // disabled since this test was doing nothing. i tried to fix it but i'm not sure … … 26 26 equals( x, what???, "Check for \\r and \\n in jQuery()" ); 27 27 */ 28 28 29 29 /* // Disabled until we add this functionality in 30 30 var pass = true; … … 42 42 var div = $("<div/><hr/><code/><b/>"); 43 43 equals( div.length, 4, "Correct number of elements generated for div hr code b" ); 44 44 45 45 // can actually yield more than one, when iframes are included, the window is an array as well 46 46 equals( $(window).length, 1, "Correct number of elements generated for window" ); 47 47 48 48 equals( $(document).length, 1, "Correct number of elements generated for document" ); 49 49 50 50 equals( $([1,2,3]).get(1), 2, "Test passing an array to the factory" ); 51 51 52 52 equals( $(document.body).get(0), $('body').get(0), "Test passing an html node to the factory" ); 53 53 }); … … 91 91 test("noConflict", function() { 92 92 expect(6); 93 93 94 94 var old = jQuery; 95 95 var newjQuery = jQuery.noConflict(); … … 157 157 158 158 var first = document.body.firstChild; 159 159 160 160 // Normal elements are reported ok everywhere 161 161 ok( !jQuery.isFunction(first), "A normal DOM Element" ); … … 207 207 $("body").append(s); 208 208 ok( foo, "Executing a scripts contents in the right context" ); 209 209 210 210 reset(); 211 211 ok( $("<link rel='stylesheet'/>")[0], "Creating a link" ); 212 212 213 213 reset(); 214 214 … … 231 231 expect(2); 232 232 stop(); 233 $.get('data/dashboard.xml', function(xml) { 233 $.get('data/dashboard.xml', function(xml) { 234 234 // tests for #1419 where IE was a problem 235 235 equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" ); … … 270 270 // use $([]).add(form.elements) instead. 271 271 //equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" ); 272 272 273 273 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>")); 274 274 equals( x[0].id, "x1", "Check on-the-fly element1" ); 275 275 equals( x[1].id, "x2", "Check on-the-fly element2" ); 276 276 277 277 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>"); 278 278 equals( x[0].id, "x1", "Check on-the-fly element1" ); 279 279 equals( x[1].id, "x2", "Check on-the-fly element2" ); 280 280 281 281 var notDefined; 282 282 equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing" ); 283 283 284 284 // Added after #2811 285 285 equals( $([]).add([window,document,document.body,document]).length, 3, "Pass an array" ); … … 302 302 test("index(Object)", function() { 303 303 expect(10); 304 304 305 305 var elements = $([window, document]), 306 306 inputElements = $('#radio1,#radio2,#check1,#check2'); 307 307 308 308 equals( elements.index(window), 0, "Check for index of elements" ); 309 309 equals( elements.index(document), 1, "Check for index of elements" ); … … 314 314 equals( inputElements.index(window), -1, "Check for not found index" ); 315 315 equals( inputElements.index(document), -1, "Check for not found index" ); 316 316 317 317 // enabled since [5500] 318 318 equals( elements.index( elements ), 0, "Pass in a jQuery object" ); … … 321 321 322 322 test("attr(String)", function() { 323 expect(2 0);323 expect(26); 324 324 equals( $('#text1').attr('value'), "Test", 'Check for value attribute' ); 325 325 equals( $('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' ); … … 341 341 equals( $('#foo').attr('nodeName'), 'DIV', 'Check for nodeName attribute' ); 342 342 equals( $('#foo').attr('tagName'), 'DIV', 'Check for tagName attribute' ); 343 343 344 344 $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path 345 345 equals( $('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' ); 346 347 348 // Related to [5574] and [5683] 349 var body = document.body, $body = $(body); 350 351 ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' ); 352 ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' ); 353 354 body.setAttribute('foo', 'baz'); 355 equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' ); 356 357 body.foo = 'bar'; 358 equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' ); 359 360 $body.attr('foo','cool'); 361 equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' ); 362 363 body.foo = undefined; 364 ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' ); 365 366 body.removeAttribute('foo'); // Cleanup 346 367 }); 347 368 … … 385 406 equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" ); 386 407 387 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" ); 388 408 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" ); 409 389 410 $("#name").attr('name', 'something'); 390 411 equals( $("#name").attr('name'), 'something', 'Set name attribute' ); … … 444 465 expect(2); 445 466 stop(); 446 $.get('data/dashboard.xml', function(xml) { 467 $.get('data/dashboard.xml', function(xml) { 447 468 var titles = []; 448 469 $('tab', xml).each(function() { … … 458 479 test("css(String|Hash)", function() { 459 480 expect(19); 460 481 461 482 equals( $('#main').css("display"), 'none', 'Check for css property "display"'); 462 483 463 484 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible'); 464 485 $('#foo').css({display: 'none'}); … … 466 487 $('#foo').css({display: 'block'}); 467 488 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible'); 468 489 469 490 $('#floatTest').css({styleFloat: 'right'}); 470 491 equals( $('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right'); … … 475 496 $('#floatTest').css({'font-size': '30px'}); 476 497 equals( $('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px'); 477 498 478 499 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) { 479 500 $('#foo').css({opacity: n}); … … 481 502 $('#foo').css({opacity: parseFloat(n)}); 482 503 equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); 483 }); 504 }); 484 505 $('#foo').css({opacity: ''}); 485 506 equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" ); … … 493 514 $('#foo').css('display', 'block'); 494 515 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible'); 495 516 496 517 $('#floatTest').css('styleFloat', 'left'); 497 518 equals( $('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left'); … … 502 523 $('#floatTest').css('font-size', '20px'); 503 524 equals( $('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px'); 504 525 505 526 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) { 506 527 $('#foo').css('opacity', n); … … 559 580 $div.hide(); 560 581 equals($div.width(), 30, "Test hidden div"); 561 582 562 583 $div.css({ display: "", border: "", padding: "" }); 563 584 564 585 $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" }); 565 586 equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding"); … … 587 608 $div.hide(); 588 609 equals($div.height(), 30, "Test hidden div"); 589 610 590 611 $div.css({ display: "", border: "", padding: "", height: "1px" }); 591 612 }); … … 609 630 ok( result.is('ol'), 'Check for element wrapping' ); 610 631 equals( result.text(), defaultText, 'Check for element wrapping' ); 611 612 reset(); 613 $('#check1').click(function() { 614 var checkbox = this; 632 633 reset(); 634 $('#check1').click(function() { 635 var checkbox = this; 615 636 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); 616 637 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' ); … … 667 688 equals( result.text(), defaultText + 'buga', 'Check if text appending works' ); 668 689 equals( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element'); 669 690 670 691 reset(); 671 692 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; 672 693 $('#sap').append(document.getElementById('first')); 673 694 equals( expected, $('#sap').text(), "Check for appending of element" ); 674 695 675 696 reset(); 676 697 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; 677 698 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]); 678 699 equals( expected, $('#sap').text(), "Check for appending of array of elements" ); 679 700 680 701 reset(); 681 702 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; … … 695 716 ok( $("#sap").append(""), "Check for appending an empty string." ); 696 717 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." ); 697 718 698 719 reset(); 699 720 $("#sap").append(document.getElementById('form')); … … 709 730 710 731 ok( pass, "Test for appending a DOM node to the contents of an IFrame" ); 711 732 712 733 reset(); 713 734 $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>'); 714 735 t( 'Append legend', '#legend', ['legend'] ); 715 736 716 737 reset(); 717 738 $('#select1').append('<OPTION>Test</OPTION>'); 718 739 equals( $('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" ); 719 740 720 741 $('#table').append('<colgroup></colgroup>'); 721 742 ok( $('#table colgroup').length, "Append colgroup" ); 722 743 723 744 $('#table colgroup').append('<col/>'); 724 745 ok( $('#table colgroup col').length, "Append col" ); 725 746 726 747 reset(); 727 748 $('#table').append('<caption></caption>'); … … 732 753 .append('<select id="appendSelect1"></select>') 733 754 .append('<select id="appendSelect2"><option>Test</option></select>'); 734 755 735 756 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] ); 736 757 … … 751 772 equals( $("#first").text(), defaultText + 'buga', 'Check if text appending works' ); 752 773 equals( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element'); 753 774 754 775 reset(); 755 776 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; 756 777 $(document.getElementById('first')).appendTo('#sap'); 757 778 equals( expected, $('#sap').text(), "Check for appending of element" ); 758 779 759 780 reset(); 760 781 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; 761 782 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap'); 762 783 equals( expected, $('#sap').text(), "Check for appending of array of elements" ); 763 784 764 785 reset(); 765 786 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; 766 787 $("#first, #yahoo").appendTo('#sap'); 767 788 equals( expected, $('#sap').text(), "Check for appending of jQuery object" ); 768 789 769 790 reset(); 770 791 $('#select1').appendTo('#foo'); … … 778 799 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' ); 779 800 equals( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element'); 780 801 781 802 reset(); 782 803 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; … … 788 809 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]); 789 810 equals( expected, $('#sap').text(), "Check for prepending of array of elements" ); 790 811 791 812 reset(); 792 813 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; … … 801 822 equals( $('#first').text(), 'buga' + defaultText, 'Check if text prepending works' ); 802 823 equals( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element'); 803 824 804 825 reset(); 805 826 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; … … 811 832 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap'); 812 833 equals( expected, $('#sap').text(), "Check for prepending of array of elements" ); 813 834 814 835 reset(); 815 836 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; 816 837 $("#yahoo, #first").prependTo('#sap'); 817 838 equals( expected, $('#sap').text(), "Check for prepending of jQuery object" ); 818 839 819 840 reset(); 820 841 $('<select id="prependSelect1"></select>').prependTo('form:last'); 821 842 $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last'); 822 843 823 844 t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] ); 824 845 }); … … 829 850 $('#yahoo').before('<b>buga</b>'); 830 851 equals( expected, $('#en').text(), 'Insert String before' ); 831 852 832 853 reset(); 833 854 expected = "This is a normal link: Try them out:Yahoo"; 834 855 $('#yahoo').before(document.getElementById('first')); 835 856 equals( expected, $('#en').text(), "Insert element before" ); 836 857 837 858 reset(); 838 859 expected = "This is a normal link: Try them out:diveintomarkYahoo"; 839 860 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]); 840 861 equals( expected, $('#en').text(), "Insert array of elements before" ); 841 862 842 863 reset(); 843 864 expected = "This is a normal link: Try them out:diveintomarkYahoo"; … … 851 872 $('<b>buga</b>').insertBefore('#yahoo'); 852 873 equals( expected, $('#en').text(), 'Insert String before' ); 853 874 854 875 reset(); 855 876 expected = "This is a normal link: Try them out:Yahoo"; 856 877 $(document.getElementById('first')).insertBefore('#yahoo'); 857 878 equals( expected, $('#en').text(), "Insert element before" ); 858 879 859 880 reset(); 860 881 expected = "This is a normal link: Try them out:diveintomarkYahoo"; 861 882 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo'); 862 883 equals( expected, $('#en').text(), "Insert array of elements before" ); 863 884 864 885 reset(); 865 886 expected = "This is a normal link: Try them out:diveintomarkYahoo"; … … 873 894 $('#yahoo').after('<b>buga</b>'); 874 895 equals( expected, $('#en').text(), 'Insert String after' ); 875 896 876 897 reset(); 877 898 expected = "This is a normal link: YahooTry them out:"; … … 883 904 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]); 884 905 equals( expected, $('#en').text(), "Insert array of elements after" ); 885 906 886 907 reset(); 887 908 expected = "This is a normal link: YahooTry them out:diveintomark"; … … 895 916 $('<b>buga</b>').insertAfter('#yahoo'); 896 917 equals( expected, $('#en').text(), 'Insert String after' ); 897 918 898 919 reset(); 899 920 expected = "This is a normal link: YahooTry them out:"; … … 905 926 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo'); 906 927 equals( expected, $('#en').text(), "Insert array of elements after" ); 907 928 908 929 reset(); 909 930 expected = "This is a normal link: YahooTry them out:diveintomark"; … … 917 938 ok( $("#replace")[0], 'Replace element with string' ); 918 939 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' ); 919 940 920 941 reset(); 921 942 $('#yahoo').replaceWith(document.getElementById('first')); … … 928 949 ok( $("#mark")[0], 'Replace element with array of elements' ); 929 950 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); 930 951 931 952 reset(); 932 953 $('#yahoo').replaceWith($("#first, #mark")); … … 941 962 ok( $("#replace")[0], 'Replace element with string' ); 942 963 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' ); 943 964 944 965 reset(); 945 966 $(document.getElementById('first')).replaceAll("#yahoo"); … … 952 973 ok( $("#mark")[0], 'Replace element with array of elements' ); 953 974 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); 954 975 955 976 reset(); 956 977 $("#first, #mark").replaceAll("#yahoo"); … … 964 985 equals( 'Yahoo', $('#yahoo').parent().end().text(), 'Check for end' ); 965 986 ok( $('#yahoo').end(), 'Check for end with nothing to end' ); 966 987 967 988 var x = $('#yahoo'); 968 989 x.parent(); … … 986 1007 equals( 'This is a normal link: Yahoo', $('#en').text(), 'Reassert text for #en' ); 987 1008 988 var cloneTags = [ 989 "<table/>", "<tr/>", "<td/>", "<div/>", 1009 var cloneTags = [ 1010 "<table/>", "<tr/>", "<td/>", "<div/>", 990 1011 "<button/>", "<ul/>", "<ol/>", "<li/>", 991 1012 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>", … … 1041 1062 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' ); 1042 1063 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' ); 1043 1064 1044 1065 // test is() with comma-seperated expressions 1045 1066 ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); … … 1074 1095 isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); 1075 1096 equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); 1076 1097 1077 1098 var nullUndef; 1078 1099 nullUndef = jQuery.extend({}, options, { xnumber2: null }); 1079 1100 ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied"); 1080 1101 1081 1102 nullUndef = jQuery.extend({}, options, { xnumber2: undefined }); 1082 1103 ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied"); 1083 1104 1084 1105 nullUndef = jQuery.extend({}, options, { xnumber0: null }); 1085 1106 ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted"); 1086 1107 1087 1108 var target = {}; 1088 1109 var recursive = { foo:target, bar:5 }; … … 1137 1158 $("#text1").val('test'); 1138 1159 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" ); 1139 1160 1140 1161 $("#select1").val("3"); 1141 1162 equals( $("#select1").val(), "3", "Check for modified (via val(String)) value of select element" ); … … 1164 1185 var j = $("#nonnodes").contents(); 1165 1186 j.html("<b>bold</b>"); 1166 1187 1167 1188 // this is needed, or the expando added by jQuery unique will yield a different html 1168 j.find('b').removeData(); 1189 j.find('b').removeData(); 1169 1190 equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); 1170 1191 … … 1207 1228 equals( $("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); 1208 1229 isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')"); 1209 1230 1210 1231 var selects = $("#form select"); 1211 1232 isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element"); … … 1223 1244 expect(5); 1224 1245 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); 1225 isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 1246 isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 1226 1247 isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); 1227 1248 isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" ); … … 1244 1265 isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" ); 1245 1266 }); 1246 1267 1247 1268 test("parents([String])", function() { 1248 1269 expect(5); … … 1261 1282 equals( $("#ap").next("div, p")[0].id, "foo", "Multiple filters" ); 1262 1283 }); 1263 1284 1264 1285 test("prev([String])", function() { 1265 1286 expect(4); … … 1277 1298 }); 1278 1299 ok( pass, "Show" ); 1279 1300 1280 1301 $("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>'); 1281 1302 var test = { … … 1295 1316 "li" : $.browser.msie ? "block" : "list-item" 1296 1317 }; 1297 1318 1298 1319 $.each(test, function(selector, expected) { 1299 1320 var elem = $(selector, "#show-tests").show(); … … 1326 1347 } 1327 1348 ok( pass, "Remove Class" ); 1328 1349 1329 1350 reset(); 1330 1351 var div = $("div").addClass("test").addClass("foo").addClass("bar"); … … 1335 1356 } 1336 1357 ok( pass, "Remove multiple classes" ); 1337 1358 1338 1359 reset(); 1339 1360 var div = $("div:eq(0)").addClass("test").removeClass(""); <1340 1361 ok( div.is('.test'), "Empty string passed to removeClass" );
