X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=ba45ea608373174cc8116b91aba3b1cd93ec961f;hb=7c04a64016c1f295dfdf4e731f693f8400a987bc;hp=80e92e6bec958a4056c64087ab807f78956b3fe7;hpb=77da94552e94925e990d058ed81419d0835747ce;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 80e92e6..ba45ea6 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -8,39 +8,115 @@ test("Basic requirements", function() { ok( document.getElementsByTagName, "getElementsByTagName" ); ok( RegExp, "RegExp" ); ok( jQuery, "jQuery" ); - ok( $, "$()" ); + ok( $, "$" ); }); -test("$()", function() { - expect(4); - - var main = $("#main"); - isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); - +test("jQuery()", function() { + expect(8); + + var main = jQuery("#main"); + isSet( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); + /* // disabled since this test was doing nothing. i tried to fix it but i'm not sure // what the expected behavior should even be. FF returns "\n" for the text node // make sure this is handled - var crlfContainer = $('

\r\n

'); + var crlfContainer = jQuery('

\r\n

'); var x = crlfContainer.contents().get(0).nodeValue; equals( x, what???, "Check for \\r and \\n in jQuery()" ); */ - + /* // Disabled until we add this functionality in var pass = true; try { - $("
Testing
").appendTo(document.getElementById("iframe").contentDocument.body); + jQuery("
Testing
").appendTo(document.getElementById("iframe").contentDocument.body); } catch(e){ pass = false; } - ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ + ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ - var code = $(""); + var code = jQuery(""); equals( code.length, 1, "Correct number of elements generated for code" ); - var img = $(""); + var img = jQuery(""); equals( img.length, 1, "Correct number of elements generated for img" ); - var div = $("

"); + var div = jQuery("

"); equals( div.length, 4, "Correct number of elements generated for div hr code b" ); + + // can actually yield more than one, when iframes are included, the window is an array as well + equals( jQuery(window).length, 1, "Correct number of elements generated for window" ); + + equals( jQuery(document).length, 1, "Correct number of elements generated for document" ); + + equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); + + equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" ); +}); + +test("selector state", function() { + expect(30); + + var test; + + test = jQuery(); + equals( test.selector, "", "Empty jQuery Selector" ); + equals( test.context, document, "Empty jQuery Context" ); + + test = jQuery(document); + equals( test.selector, "", "Document Selector" ); + equals( test.context, document, "Document Context" ); + + test = jQuery(document.body); + equals( test.selector, "", "Body Selector" ); + equals( test.context, document.body, "Body Context" ); + + test = jQuery("#main"); + equals( test.selector, "#main", "#main Selector" ); + equals( test.context, document, "#main Context" ); + + test = jQuery("#notfoundnono"); + equals( test.selector, "#notfoundnono", "#notfoundnono Selector" ); + equals( test.context, document, "#notfoundnono Context" ); + + test = jQuery("#main", document); + equals( test.selector, "#main", "#main Selector" ); + equals( test.context, document, "#main Context" ); + + test = jQuery("#main", document.body); + equals( test.selector, "#main", "#main Selector" ); + equals( test.context, document.body, "#main Context" ); + + // Test cloning + test = jQuery(test); + equals( test.selector, "#main", "#main Selector" ); + equals( test.context, document.body, "#main Context" ); + + test = jQuery(document.body).find("#main"); + equals( test.selector, "#main", "#main find Selector" ); + equals( test.context, document.body, "#main find Context" ); + + test = jQuery("#main").filter("div"); + equals( test.selector, "#main.filter(div)", "#main filter Selector" ); + equals( test.context, document, "#main filter Context" ); + + test = jQuery("#main").not("div"); + equals( test.selector, "#main.not(div)", "#main not Selector" ); + equals( test.context, document, "#main not Context" ); + + test = jQuery("#main").filter("div").not("div"); + equals( test.selector, "#main.filter(div).not(div)", "#main filter, not Selector" ); + equals( test.context, document, "#main filter, not Context" ); + + test = jQuery("#main").filter("div").not("div").end(); + equals( test.selector, "#main.filter(div)", "#main filter, not, end Selector" ); + equals( test.context, document, "#main filter, not, end Context" ); + + test = jQuery("#main").parent("body"); + equals( test.selector, "#main.parent(body)", "#main parent Selector" ); + equals( test.context, document, "#main parent Context" ); + + test = jQuery("#main").eq(0); + equals( test.selector, "#main.slice(0,1)", "#main eq Selector" ); + equals( test.context, document, "#main eq Context" ); }); test("browser", function() { @@ -74,34 +150,31 @@ test("browser", function() { }; for (var i in browsers) { var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check - version = v ? v[1] : null; + var version = v ? v[1] : null; equals( version, browsers[i], "Checking UA string" ); } }); 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." ); + var $$ = jQuery; - jQuery = $ = old; + equals( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); + equals( jQuery, $$, "Make sure jQuery wasn't touched." ); + equals( $, original$, "Make sure $ was reverted." ); - newjQuery = jQuery.noConflict(true); + jQuery = $ = $$; - ok( newjQuery == old, "noConflict returned the jQuery object" ); - ok( jQuery == "jQuery", "Make sure jQuery was reverted." ); - ok( $ == "$", "Make sure $ was reverted." ); + equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); + equals( jQuery, originaljQuery, "Make sure jQuery was reverted." ); + equals( $, original$, "Make sure $ was reverted." ); - jQuery = $ = old; + jQuery = $$; }); test("isFunction", function() { - expect(21); + expect(19); // Make sure that false values return false ok( !jQuery.isFunction(), "No Value" ); @@ -112,10 +185,10 @@ test("isFunction", function() { // Check built-ins // Safari uses "(Internal Function)" - ok( jQuery.isFunction(String), "String Function" ); - ok( jQuery.isFunction(Array), "Array Function" ); - ok( jQuery.isFunction(Object), "Object Function" ); - ok( jQuery.isFunction(Function), "Function Function" ); + ok( jQuery.isFunction(String), "String Function("+String+")" ); + ok( jQuery.isFunction(Array), "Array Function("+Array+")" ); + ok( jQuery.isFunction(Object), "Object Function("+Object+")" ); + ok( jQuery.isFunction(Function), "Function Function("+Function+")" ); // When stringified, this could be misinterpreted var mystr = "function"; @@ -139,7 +212,8 @@ test("isFunction", function() { ok( !jQuery.isFunction(obj), "Object Element" ); // IE says this is an object - ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); var nodes = document.body.childNodes; @@ -147,7 +221,7 @@ test("isFunction", function() { ok( !jQuery.isFunction(nodes), "childNodes Property" ); var first = document.body.firstChild; - + // Normal elements are reported ok everywhere ok( !jQuery.isFunction(first), "A normal DOM Element" ); @@ -156,7 +230,8 @@ test("isFunction", function() { document.body.appendChild( input ); // IE says this is an object - ok( jQuery.isFunction(input.focus), "A default function property" ); + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(input.focus), "A default function property" ); document.body.removeChild( input ); @@ -185,47 +260,48 @@ test("isFunction", function() { }); }); -var foo = false; - -test("$('html')", function() { - expect(6); +test("jQuery('html')", function() { + expect(8); reset(); - foo = false; - var s = $("")[0]; + jQuery.foo = false; + var s = jQuery("")[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" ); - + ok( !jQuery.foo, "Make sure the script wasn't executed prematurely" ); + jQuery("body").append(""); + ok( jQuery.foo, "Executing a scripts contents in the right context" ); + reset(); + ok( jQuery("")[0], "Creating a link" ); + + ok( !jQuery("'); - - $("#main").html('foo
'); - - // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959 - $("#main").html("