X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Ftraversing.js;h=a235bbd5ae306df48386ef8688d90f33e8aca596;hb=4e27f17007c2329e31b449e61bb31197b90a37f1;hp=7b046e3d10290f1d8e6fb69b6c62e06a8b4df810;hpb=9e60fec46b2394541f75da3e333094d41069e84f;p=jquery.git diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 7b046e3..a235bbd 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -152,7 +152,43 @@ test("not(jQuery)", function() { expect(1); same( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); -}) +}); + +test("has(Element)", function() { + expect(2); + + var obj = jQuery("#main").has(jQuery("#sndp")[0]); + same( obj.get(), q("main"), "Keeps elements that have the element as a descendant" ); + + var multipleParent = jQuery("#main, #header").has(jQuery("#sndp")[0]); + same( obj.get(), q("main"), "Does not include elements that do not have the element as a descendant" ); +}); + +test("has(Selector)", function() { + expect(3); + + var obj = jQuery("#main").has("#sndp"); + same( obj.get(), q("main"), "Keeps elements that have any element matching the selector as a descendant" ); + + var multipleParent = jQuery("#main, #header").has("#sndp"); + same( obj.get(), q("main"), "Does not include elements that do not have the element as a descendant" ); + + var multipleHas = jQuery("#main").has("#sndp, #first"); + same( multipleHas.get(), q("main"), "Only adds elements once" ); +}); + +test("has(Arrayish)", function() { + expect(3); + + var simple = jQuery("#main").has(jQuery("#sndp")); + same( simple.get(), q("main"), "Keeps elements that have any element in the jQuery list as a descendant" ); + + var multipleParent = jQuery("#main, #header").has(jQuery("#sndp")); + same( multipleParent.get(), q("main"), "Does not include elements that do not have an element in the jQuery list as a descendant" ); + + var multipleHas = jQuery("#main").has(jQuery("#sndp, #first")); + same( simple.get(), q("main"), "Only adds elements once" ); +}); test("andSelf()", function() { expect(4);