X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=test%2Funit%2Fcore.js;h=289a8bace0f9318d874607bd22bd813703d9c8ec;hb=e73990a566fcb2dac71e1a25ec83382645adc5b7;hp=2f775cd771dcc508a4bd8862528bc7e9e453a1a2;hpb=4a4d049df9be6d0df5a331cb08d7b95564bc5ee2;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 2f775cd..289a8ba 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -463,7 +463,7 @@ test("attr(Hash)", function() { }); test("attr(String, Object)", function() { - expect(19); + expect(21); var div = jQuery("div").attr("foo", "bar"), fail = false; for ( var i = 0; i < div.size(); i++ ) { @@ -537,6 +537,16 @@ test("attr(String, Object)", function() { } ok( thrown, "Exception thrown when trying to change type property" ); equals( "checkbox", check.attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" ); + + var button = jQuery("#button"); + var thrown = false; + try { + button.attr('type','submit'); + } catch(e) { + thrown = true; + } + ok( thrown, "Exception thrown when trying to change type property" ); + equals( "button", button.attr('type'), "Verify that you can't change the type of a button element" ); }); if ( !isLocal ) { @@ -694,26 +704,27 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct }); test("width()", function() { - expect(8); + expect(6); var $div = jQuery("#nothiddendiv"); $div.width(30); equals($div.width(), 30, "Test set to 30 correctly"); + $div.hide(); + equals($div.width(), 30, "Test hidden div"); + $div.show(); $div.width(-1); // handle negative numbers by ignoring #1599 equals($div.width(), 30, "Test negative width ignored"); $div.css("padding", "20px"); equals($div.width(), 30, "Test padding specified with pixels"); $div.css("border", "2px solid #fff"); equals($div.width(), 30, "Test border specified with pixels"); - $div.css("padding", "2em"); - equals($div.width(), 30, "Test padding specified with ems"); - $div.css("border", "1em solid #fff"); + //$div.css("padding", "2em"); + //equals($div.width(), 30, "Test padding specified with ems"); + //$div.css("border", "1em solid #fff"); //DISABLED - Opera 9.6 fails this test, returns 8 //equals($div.width(), 30, "Test border specified with ems"); - $div.css("padding", "2%"); - equals($div.width(), 30, "Test padding specified with percent"); - $div.hide(); - equals($div.width(), 30, "Test hidden div"); + //$div.css("padding", "2%"); + //equals($div.width(), 30, "Test padding specified with percent"); $div.css({ display: "", border: "", padding: "" }); @@ -723,26 +734,27 @@ test("width()", function() { }); test("height()", function() { - expect(7); + expect(5); var $div = jQuery("#nothiddendiv"); $div.height(30); equals($div.height(), 30, "Test set to 30 correctly"); + $div.hide(); + equals($div.height(), 30, "Test hidden div"); + $div.show(); $div.height(-1); // handle negative numbers by ignoring #1599 equals($div.height(), 30, "Test negative height ignored"); $div.css("padding", "20px"); equals($div.height(), 30, "Test padding specified with pixels"); $div.css("border", "2px solid #fff"); equals($div.height(), 30, "Test border specified with pixels"); - $div.css("padding", "2em"); - equals($div.height(), 30, "Test padding specified with ems"); - $div.css("border", "1em solid #fff"); + //$div.css("padding", "2em"); + //equals($div.height(), 30, "Test padding specified with ems"); + //$div.css("border", "1em solid #fff"); //DISABLED - Opera 9.6 fails this test, returns 8 //equals($div.height(), 30, "Test border specified with ems"); - $div.css("padding", "2%"); - equals($div.height(), 30, "Test padding specified with percent"); - $div.hide(); - equals($div.height(), 30, "Test hidden div"); + //$div.css("padding", "2%"); + //equals($div.height(), 30, "Test padding specified with percent"); $div.css({ display: "", border: "", padding: "", height: "1px" }); }); @@ -907,7 +919,7 @@ test("append(String|Element|Array<Element>|jQuery)", function() { }); test("appendTo(String|Element|Array<Element>|jQuery)", function() { - expect(7); + expect(12); var defaultText = 'Try them out:' jQuery('buga').appendTo('#first'); equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' ); @@ -934,6 +946,27 @@ test("appendTo(String|Element|Array<Element>|jQuery)", function() { reset(); jQuery('#select1').appendTo('#foo'); t( 'Append select', '#foo select', ['select1'] ); + + reset(); + var div = jQuery("
").click(function(){ + ok(true, "Running a cloned click."); + }); + div.appendTo("#main, #moretests"); + + jQuery("#main div:last").click(); + jQuery("#moretests div:last").click(); + + reset(); + var div = jQuery("
").appendTo("#main, #moretests"); + + equals( div.length, 2, "appendTo returns the inserted elements" ); + + div.addClass("test"); + + ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" ); + ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" ); + + reset(); }); test("prepend(String|Element|Array<Element>|jQuery)", function() { @@ -973,12 +1006,12 @@ test("prependTo(String|Element|Array<Element>|jQuery)", function() { reset(); expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; - jQuery([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap'); + jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap'); equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" ); reset(); - expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; - jQuery("#yahoo, #first").prependTo('#sap'); + expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; + jQuery("#first, #yahoo").prependTo('#sap'); equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" ); reset(); @@ -1067,12 +1100,12 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() { reset(); expected = "This is a normal link: YahooTry them out:diveintomark"; - jQuery([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo'); + jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo'); equals( expected, jQuery('#en').text(), "Insert array of elements after" ); reset(); - expected = "This is a normal link: YahooTry them out:diveintomark"; - jQuery("#mark, #first").insertAfter('#yahoo'); + expected = "This is a normal link: YahoodiveintomarkTry them out:"; + jQuery("#first, #mark").insertAfter('#yahoo'); equals( expected, jQuery('#en').text(), "Insert jQuery after" ); }); @@ -1530,6 +1563,9 @@ test("show()", function() { ok( pass, "Show" ); jQuery("#main").append('

'); + + var old = jQuery("#show-tests table").show().css("display") !== "table"; + var test = { "div" : "block", "p" : "block", @@ -1537,14 +1573,14 @@ test("show()", function() { "code" : "inline", "pre" : "block", "span" : "inline", - "table" : jQuery.browser.msie ? "block" : "table", - "thead" : jQuery.browser.msie ? "block" : "table-header-group", - "tbody" : jQuery.browser.msie ? "block" : "table-row-group", - "tr" : jQuery.browser.msie ? "block" : "table-row", - "th" : jQuery.browser.msie ? "block" : "table-cell", - "td" : jQuery.browser.msie ? "block" : "table-cell", + "table" : old ? "block" : "table", + "thead" : old ? "block" : "table-header-group", + "tbody" : old ? "block" : "table-row-group", + "tr" : old ? "block" : "table-row", + "th" : old ? "block" : "table-cell", + "td" : old ? "block" : "table-cell", "ul" : "block", - "li" : jQuery.browser.msie ? "block" : "list-item" + "li" : old ? "block" : "list-item" }; jQuery.each(test, function(selector, expected) { @@ -1662,13 +1698,6 @@ test("jQuery.each(Object,Function)", function() { equals( total, 3, "Looping over an object, with break" ); }); -test("jQuery.prop", function() { - expect(2); - var handle = function() { return this.id }; - equals( jQuery.prop(jQuery("#ap")[0], handle), "ap", "Check with Function argument" ); - equals( jQuery.prop(jQuery("#ap")[0], "value"), "value", "Check with value argument" ); -}); - test("jQuery.className", function() { expect(6); var x = jQuery("

Hi

")[0]; @@ -1687,7 +1716,7 @@ test("jQuery.className", function() { }); test("remove()", function() { - expect(6); + expect(7); jQuery("#ap").children().remove(); ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); equals( jQuery("#ap").children().length, 0, "Check remove" ); @@ -1697,6 +1726,9 @@ test("remove()", function() { ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); equals( jQuery("#ap").children().length, 1, "Check filtered remove" ); + jQuery("#ap").children().remove("a, code"); + equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" ); + // using contents will get comments regular, text, and comment nodes equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" ); jQuery("#nonnodes").contents().remove();