X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=a5a59c3a1c0f4de05f654a214bb0ab90f844cb8a;hb=d0fae71464427d9b9e29a5e3fa27729675bef95a;hp=30fff7731ff5ecee17c575fff6b0cc5f1f28f0e9;hpb=fc51e14b810474fe9ed0b03bed5eddc82e9f7fde;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 30fff77..a5a59c3 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -43,6 +43,42 @@ test("$()", function() { equals( div.length, 4, "Correct number of elements generated for div hr code b" ); }); +test("browser", function() { + expect(13); + var browsers = { + //Internet Explorer + "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0", + "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0", + /** Failing #1876 + * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0", + */ + //Browsers with Gecko engine + //Mozilla + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12", + //Firefox + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3", + //Netscape + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5", + //Flock + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11", + //Opera browser + "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20", + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20", + "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20", + //WebKit engine + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8", + //Other user agent string + "Other browser's user agent 1.0":null + }; + 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; + equals( version, browsers[i], "Checking UA string" ); + } +}); + test("noConflict", function() { expect(6); @@ -181,6 +217,7 @@ test("$('html', context)", function() { equals($span.length, 1, "Verify a span created with a div context works, #1763"); }); +if ( !isLocal ) { test("$(selector, xml).text(str) - Loaded via XML document", function() { expect(2); stop(); @@ -192,6 +229,7 @@ test("$(selector, xml).text(str) - Loaded via XML document", function() { start(); }); }); +} test("length", function() { expect(1); @@ -218,6 +256,10 @@ test("add(String|Element|Array|undefined)", function() { isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" ); + + // For the time being, we're discontinuing support for $(form.elements) since it's ambiguous in IE + // use $([]).add(form.elements) instead. + //equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" ); var x = $([]).add($("

xxx

")).add($("

xxx

")); ok( x[0].id == "x1", "Check on-the-fly element1" ); @@ -913,7 +955,7 @@ test("find(String)", function() { }); test("clone()", function() { - expect(6); + expect(4); ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' ); var clone = $('#yahoo').clone(); ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' ); @@ -921,7 +963,11 @@ test("clone()", function() { // using contents will get comments regular, text, and comment nodes var cl = $("#nonnodes").contents().clone(); ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); +}); +if (!isLocal) { +test("clone() on XML nodes", function() { + expect(2); stop(); $.get("data/dashboard.xml", function (xml) { var root = $(xml.documentElement).clone(); @@ -932,6 +978,7 @@ test("clone()", function() { start(); }); }); +} test("is(String)", function() { expect(26); @@ -1029,11 +1076,12 @@ test("$.extend(Object, Object)", function() { }); test("val()", function() { - expect(3); + expect(4); ok( $("#text1").val() == "Test", "Check for value of input element" ); ok( !$("#text1").val() == "", "Check for value of input element" ); // ticket #1714 this caused a JS error in IE ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" ); + ok( $([]).val() === undefined, "Check an empty jQuery object will return undefined from val" ); }); test("val(String)", function() { @@ -1276,7 +1324,7 @@ test("text(String)", function() { }); test("$.each(Object,Function)", function() { - expect(8); + expect(12); $.each( [0,1,2], function(i, n){ ok( i == n, "Check array iteration" ); }); @@ -1288,6 +1336,19 @@ test("$.each(Object,Function)", function() { $.each( { name: "name", lang: "lang" }, function(i, n){ ok( i == n, "Check object iteration" ); }); + + var total = 0; + jQuery.each([1,2,3], function(i,v){ total += v; }); + ok( total == 6, "Looping over an array" ); + total = 0; + jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; }); + ok( total == 3, "Looping over an array, with break" ); + total = 0; + jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; }); + ok( total == 6, "Looping over an object" ); + total = 0; + jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; }); + ok( total == 3, "Looping over an object, with break" ); }); test("$.prop", function() {