X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=96b5d4079134fff49c4e5febdded65bcd599d66d;hb=e2ef3df86d5f54274bf2b779d882c30aa0886bfe;hp=db47856095e3a2f2ce98af219b3b24c083e7f2bb;hpb=6728e3cf74d02794113deb0af70a5f9a7caa2241;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index db47856..96b5d40 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -38,6 +38,27 @@ test("$()", function() { equals( div.length, 4, "Correct number of elements generated for div hr code b" ); }); +test("noConflict", function() { + expect(6); + + var old = jQuery; + var newjQuery = jQuery.noConflict(); + + ok( newjQuery == old, "noConflict returned the jQuery object" ); + ok( jQuery == old, "Make sure jQuery wasn't touched." ); + ok( $ == "$", "Make sure $ was reverted." ); + + jQuery = $ = old; + + newjQuery = jQuery.noConflict(true); + + ok( newjQuery == old, "noConflict returned the jQuery object" ); + ok( jQuery == "jQuery", "Make sure jQuery was reverted." ); + ok( $ == "$", "Make sure $ was reverted." ); + + jQuery = $ = old; +}); + test("isFunction", function() { expect(21); @@ -123,11 +144,18 @@ test("isFunction", function() { }); }); +var foo = false; + test("$('html')", function() { - expect(2); + expect(4); reset(); - ok( $("")[0], "Creating a script" ); + foo = false; + var s = $("")[0]; + ok( s, "Creating a script" ); + ok( !foo, "Make sure the script wasn't executed prematurely" ); + $("body").append(s); + ok( foo, "Executing a scripts contents in the right context" ); reset(); ok( $("")[0], "Creating a link" ); @@ -213,15 +241,17 @@ test("attr(String)", function() { ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' ); }); -test("attr(String) in XML Files", function() { - expect(2); - stop(); - $.get("data/dashboard.xml", function(xml) { - ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" ); - ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" ); - start(); - }); -}); +if ( !isLocal ) { + test("attr(String) in XML Files", function() { + expect(2); + stop(); + $.get("data/dashboard.xml", function(xml) { + ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" ); + ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" ); + start(); + }); + }); +} test("attr(String, Function)", function() { expect(2); @@ -286,19 +316,21 @@ test("attr(String, Object)", function() { equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" ); }); -test("attr(String, Object) - Loaded via XML document", function() { - expect(2); - stop(); - $.get('data/dashboard.xml', function(xml) { - var titles = []; - $('tab', xml).each(function() { - titles.push($(this).attr('title')); - }); - ok( titles[0] == 'Location', 'attr() in XML context: Check first title' ); - ok( titles[1] == 'Users', 'attr() in XML context: Check second title' ); - start(); - }); -}); +if ( !isLocal ) { + test("attr(String, Object) - Loaded via XML document", function() { + expect(2); + stop(); + $.get('data/dashboard.xml', function(xml) { + var titles = []; + $('tab', xml).each(function() { + titles.push($(this).attr('title')); + }); + ok( titles[0] == 'Location', 'attr() in XML context: Check first title' ); + ok( titles[1] == 'Users', 'attr() in XML context: Check second title' ); + start(); + }); + }); +} test("css(String|Hash)", function() { expect(19); @@ -357,6 +389,18 @@ test("css(String, Object)", function() { ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" ); }); +test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () { + expect(4); + + var $checkedtest = $("#checkedtest"); + // IE6 was clearing "checked" in jQuery.css(elem, "height"); + jQuery.css($checkedtest[0], "height"); + ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." ); + ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." ); + ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." ); + ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." ); +}); + test("text()", function() { expect(1); var expected = "This link has class=\"blog\": Simon Willison's Weblog"; @@ -767,7 +811,7 @@ test("is(String)", function() { }); test("$.extend(Object, Object)", function() { - expect(10); + expect(11); var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, @@ -775,9 +819,9 @@ test("$.extend(Object, Object)", function() { merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" }, deep1 = { foo: { bar: true } }, deep1copy = { foo: { bar: true } }, - deep2 = { foo: { baz: true } }, - deep2copy = { foo: { baz: true } }, - deepmerged = { foo: { bar: true, baz: true } }; + deep2 = { foo: { baz: true }, foo2: document }, + deep2copy = { foo: { baz: true }, foo2: document }, + deepmerged = { foo: { bar: true, baz: true }, foo2: document }; jQuery.extend(settings, options); isObj( settings, merged, "Check if extended: settings must be extended" ); @@ -790,6 +834,7 @@ test("$.extend(Object, Object)", function() { jQuery.extend(true, deep1, deep2); isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" ); isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); + equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, @@ -813,15 +858,20 @@ test("val()", function() { }); test("val(String)", function() { - expect(2); + expect(3); document.getElementById('text1').value = "bla"; ok( $("#text1").val() == "bla", "Check for modified value of input element" ); $("#text1").val('test'); ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" ); + + $("#select1").val("3"); + ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" ); }); +var scriptorder = 0; + test("html(String)", function() { - expect(1); + expect(9); var div = $("div"); div.html("test"); var pass = true; @@ -830,8 +880,15 @@ test("html(String)", function() { } ok( pass, "Set HTML" ); - // Ccommented out until we can resolve it - // $("#main").html('').evalScripts(); + stop(); + + $("#main").html(''); + + $("#main").html('foo
'); + + $("#main").html("