X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=1ec3487d0a94a2af623fcbff862fbc864d47c3e5;hb=29bf601f3495ced43fbb6152bf9306f2618bb955;hp=451bd71c7b938b7133df26e7a4fd06832fe93eeb;hpb=c0294278db40da764a98ea1c1506548e539213c7;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 451bd71..1ec3487 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -53,7 +53,7 @@ test("jQuery()", function() { }); test("selector state", function() { - expect(26); + expect(28); var test; @@ -80,6 +80,11 @@ test("selector state", function() { 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" ); @@ -141,7 +146,7 @@ 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" ); } }); @@ -251,18 +256,16 @@ test("isFunction", function() { }); }); -var foo = false; - test("jQuery('html')", function() { expect(8); reset(); - foo = false; - var s = jQuery("")[0]; + jQuery.foo = false; + var s = jQuery("")[0]; ok( s, "Creating a script" ); - ok( !foo, "Make sure the script wasn't executed prematurely" ); - jQuery("body").append(""); - ok( foo, "Executing a scripts contents in the right context" ); + 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" ); @@ -291,9 +294,10 @@ test("jQuery(selector, xml).text(str) - Loaded via XML document", function() { stop(); jQuery.get('data/dashboard.xml', function(xml) { // tests for #1419 where IE was a problem - equals( jQuery("tab:first", xml).text(), "blabla", "Verify initial text correct" ); - jQuery("tab:first", xml).text("newtext"); - equals( jQuery("tab:first", xml).text(), "newtext", "Verify new text correct" ); + var tab = jQuery("tab", xml).eq(0); + equals( tab.text(), "blabla", "Verify initial text correct" ); + tab.text("newtext"); + equals( tab.text(), "newtext", "Verify new text correct" ); start(); }); }); @@ -454,7 +458,7 @@ test("attr(Hash)", function() { test("attr(String, Object)", function() { expect(19); - var div = jQuery("div").attr("foo", "bar"); + var div = jQuery("div").attr("foo", "bar"), fail = false; for ( var i = 0; i < div.size(); i++ ) { if ( div.get(i).getAttribute('foo') != "bar" ){ @@ -545,6 +549,62 @@ if ( !isLocal ) { }); } +test("attr('tabindex')", function() { + expect(5); + + // tabindex 0 + equals(jQuery('#listWithTabIndex').attr('tabindex'), 0, 'tabindex of 0'); + + // positive tabindex + equals(jQuery('#linkWithTabIndex').attr('tabindex'), 2, 'tabindex of 2'); + + // negative tabindex + equals(jQuery('#linkWithNegativeTabIndex').attr('tabindex'), -1, 'negative tabindex'); + + // regular element without a tabindex + equals(jQuery('#divWithNoTabIndex').attr('tabindex'), undefined, 'no tabindex, not tabbable by default'); + + // link without a tabindex + equals(jQuery('#linkWithNoTabIndex').attr('tabindex'), 0, 'no tabindex, tabbable by default'); +}); + +test("attr('tabindex', value)", function() { + expect(9); + + var element = jQuery('#divWithNoTabIndex'); + equals(element.attr('tabindex'), undefined, 'start with no tabindex'); + + // set a positive string + element.attr('tabindex', '1'); + equals(element.attr('tabindex'), 1, 'set tabindex to 1 (string)'); + + // set a zero string + element.attr('tabindex', '0'); + equals(element.attr('tabindex'), 0, 'set tabindex to 0 (string)'); + + // set a negative string + element.attr('tabindex', '-1'); + equals(element.attr('tabindex'), -1, 'set tabindex to -1 (string)'); + + // set a positive number + element.attr('tabindex', 1); + equals(element.attr('tabindex'), 1, 'set tabindex to 1 (number)'); + + // set a zero number + element.attr('tabindex', 0); + equals(element.attr('tabindex'), 0, 'set tabindex to 0 (number)'); + + // set a negative number + element.attr('tabindex', -1); + equals(element.attr('tabindex'), -1, 'set tabindex to -1 (number)'); + + element = jQuery('#linkWithTabIndex'); + equals(element.attr('tabindex'), 2, 'start with tabindex 2'); + + element.attr('tabindex', -1); + equals(element.attr('tabindex'), -1, 'set negative tabindex'); +}); + test("css(String|Hash)", function() { expect(19); @@ -839,7 +899,7 @@ test("append(String|Element|Array<Element>|jQuery)", function() { }); test("appendTo(String|Element|Array<Element>|jQuery)", function() { - expect(6); + expect(7); var defaultText = 'Try them out:' jQuery('buga').appendTo('#first'); equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' ); @@ -856,6 +916,9 @@ test("appendTo(String|Element|Array<Element>|jQuery)", function() { equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" ); reset(); + ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." ); + + reset(); expected = document.querySelectorAll ? "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" : "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; @@ -1111,10 +1174,12 @@ test("clone() on XML nodes", function() { stop(); jQuery.get("data/dashboard.xml", function (xml) { var root = jQuery(xml.documentElement).clone(); - jQuery("tab:first", xml).text("origval"); - jQuery("tab:first", root).text("cloneval"); - equals(jQuery("tab:first", xml).text(), "origval", "Check original XML node was correctly set"); - equals(jQuery("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set"); + var origTab = jQuery("tab", xml).eq(0); + var cloneTab = jQuery("tab", root).eq(0); + origTab.text("origval"); + cloneTab.text("cloneval"); + equals(origTab.text(), "origval", "Check original XML node was correctly set"); + equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set"); start(); }); }); @@ -1286,10 +1351,11 @@ test("val(String/Number)", function() { j.removeAttr("value"); }); -var scriptorder = 0; - test("html(String)", function() { expect(13); + + jQuery.scriptorder = 0; + var div = jQuery("#main > div"); div.html("test"); var pass = true; @@ -1322,7 +1388,7 @@ test("html(String)", function() { 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 - jQuery("#main").html("