X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=5101f8181a1c01dfe47aaf7eaa2984c0b5c6a173;hb=084079d2fd1c7ed3582612cc32b01346b43fb415;hp=db47856095e3a2f2ce98af219b3b24c083e7f2bb;hpb=6728e3cf74d02794113deb0af70a5f9a7caa2241;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index db47856..5101f81 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); @@ -767,7 +799,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 +807,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 +822,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 +846,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 +868,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("