X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2FcoreTest.js;h=11cb5fb1961bfca5903cfca8b2a765dfed9dafa1;hb=a69aad2242a5be4ee21955d6132247b4781d410e;hp=ed7b52ba8408908934ec2b8d40085bd15d7b1191;hpb=200319ea6b6a59daebce1cfc1d330a9d52c208c0;p=jquery.git diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index ed7b52b..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' ); @@ -192,7 +210,7 @@ test("wrap(String|Element)", function() { }); test("append(String|Element|Array<Element>|jQuery)", function() { - expect(5); + expect(9); var defaultText = 'Try them out:' var result = $('#first').append('buga'); ok( result.text() == defaultText + 'buga', 'Check if text appending works' ); @@ -212,6 +230,15 @@ test("append(String|Element|Array<Element>|jQuery)", function() { expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; $('#sap').append($("#first, #yahoo")); ok( expected == $('#sap').text(), "Check for appending of jQuery object" ); + + reset(); + $("#sap").append( 5 ); + ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" ); + + reset(); + ok( $("#sap").append([]), "Check for appending an empty array." ); + ok( $("#sap").append(""), "Check for appending an empty string." ); + ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." ); }); test("appendTo(String|Element|Array<Element>|jQuery)", function() { @@ -472,18 +499,18 @@ test("html(String)", function() { }); test("filter()", function() { - expect(5); + expect(4); isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); - isSet( $("p").filter(["#ap", "#sndp"]).get(), q("ap", "sndp"), "filter(Array<String>)" ); isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); 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").get(), q("firstp", "en", "sap", "first", "result"), "not('selector, 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)" ); }); @@ -644,7 +671,17 @@ test("empty()", function() { test("eq(), gt(), lt(), contains()", function() { ok( $("#ap a").eq(1)[0].id == "groups", "eq()" ); - ok( $("#ap a").gt(1).get(), q("groups", "anchor1", "mark"), "gt()" ); - ok( $("#ap a").lt(2).get(), q("google", "groups", "anchor1"), "lt()" ); - ok( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" ); + isSet( $("#ap a").gt(0).get(), q("groups", "anchor1", "mark"), "gt()" ); + 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