X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2FcoreTest.js;h=11cb5fb1961bfca5903cfca8b2a765dfed9dafa1;hb=a69aad2242a5be4ee21955d6132247b4781d410e;hp=f736d4d7080e3149ae7cf3e9739415142f596b08;hpb=729396e6cfb1a0495399609f5929fb630a49649d;p=jquery.git diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index f736d4d..11cb5fb 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -11,6 +11,14 @@ test("Basic requirements", function() { ok( $, "$()" ); }); +test("$()", function() { + var main = $("#main"); + isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); + + // make sure this is handled + $('

\r\n

'); +}); + test("length", function() { ok( $("div").length == 2, "Get Number of Elements Found" ); }); @@ -29,7 +37,7 @@ test("get(Number)", function() { test("add(String|Element|Array)", 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" ); var x = $([]).add($("

xxx

")).add($("

xxx

")); @@ -66,7 +74,7 @@ test("index(Object)", function() { }); test("attr(String)", function() { - expect(12); + expect(15); ok( $('#text1').attr('value') == "Test", 'Check for value attribute' ); ok( $('#text1').attr('type') == "text", 'Check for type attribute' ); ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' ); @@ -79,11 +87,19 @@ test("attr(String)", function() { ok( $('#name').attr('name') == "name", 'Check for name attribute' ); ok( $('#text1').attr('name') == "action", 'Check for name attribute' ); ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); + equals( "#2", $('#anchor2').attr('href'), 'Check for non-absolute href (an anchor)' ); + 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(1); + expect(2); ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" ); + ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index"); }); test("attr(Hash)", function() { @@ -96,7 +112,7 @@ test("attr(Hash)", function() { }); test("attr(String, Object)", function() { - expect(6); + expect(7); var div = $("div"); div.attr("foo", "bar"); var pass = true; @@ -104,6 +120,8 @@ test("attr(String, Object)", function() { if ( div.get(i).getAttribute('foo') != "bar" ) pass = false; } ok( pass, "Set Attribute" ); + + ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" ); $("#name").attr('name', 'something'); ok( $("#name").attr('name') == 'something', 'Set name attribute' ); @@ -488,10 +506,11 @@ test("filter()", function() { isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" ); }); -test("not(String)", function() { - expect(2); +test("not()", function() { + expect(3); ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" ); isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); + isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); }); @@ -656,3 +675,13 @@ test("eq(), gt(), lt(), contains()", function() { isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" ); isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" ); }); + +test("click() context", function() { + $('
  • Change location
  • ').prependTo('#firstUL').find('a').bind('click', function() { + var close = $('spanx', this); // same with $(this).find('span'); + ok( close.length == 0, "Element does not exist, length must be zero" ); + ok( !close[0], "Element does not exist, direct access to element must return undefined" ); + //console.log( close[0]); // it's the and not a element + return false; + }).click(); +}); \ No newline at end of file