aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/traversing.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-09-19 23:50:52 -0400
committertimmywil <timmywillisn@gmail.com>2011-09-19 23:50:52 -0400
commit70e2e32e0eb03607ad0c8b7752dbd7747da47164 (patch)
treea48bb145515cfe6bb5f5635fe1aa4db900aba8b1 /test/unit/traversing.js
parent2e5522a406de493f85832ed1adb57c0f4ce87a9c (diff)
downloadjquery-70e2e32e0eb03607ad0c8b7752dbd7747da47164.tar.gz
jquery-70e2e32e0eb03607ad0c8b7752dbd7747da47164.zip
Landing pull request 491. Fix #7322. Make `.is()` with a positional selector work like delegated event logic. Fixes #7322.
More Details: - https://github.com/jquery/jquery/pull/491 - http://bugs.jquery.com/ticket/7322
Diffstat (limited to 'test/unit/traversing.js')
-rw-r--r--test/unit/traversing.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/unit/traversing.js b/test/unit/traversing.js
index 1c415c02e..a3050672b 100644
--- a/test/unit/traversing.js
+++ b/test/unit/traversing.js
@@ -101,6 +101,46 @@ test("is(jQuery)", function() {
ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
});
+test("is() with positional selectors", function() {
+ expect(23);
+
+ var html = jQuery(
+ '<p id="posp"><a class="firsta" href="#"><em>first</em></a><a class="seconda" href="#"><b>test</b></a><em></em></p>'
+ ).appendTo( "body" ),
+ isit = function(sel, match, expect) {
+ equal( jQuery( sel ).is( match ), expect, "jQuery( " + sel + " ).is( " + match + " )" );
+ };
+
+ isit( "#posp", "#posp:first", true );
+ isit( "#posp", "#posp:eq(2)", false );
+ isit( "#posp", "#posp a:first", false );
+
+ isit( "#posp .firsta", "#posp a:first", true );
+ isit( "#posp .firsta", "#posp a:last", false );
+ isit( "#posp .firsta", "#posp a:even", true );
+ isit( "#posp .firsta", "#posp a:odd", false );
+ isit( "#posp .firsta", "#posp a:eq(0)", true );
+ isit( "#posp .firsta", "#posp a:eq(9)", false );
+ isit( "#posp .firsta", "#posp em:eq(0)", false );
+ isit( "#posp .firsta", "#posp em:first", false );
+ isit( "#posp .firsta", "#posp:first", false );
+
+ isit( "#posp .seconda", "#posp a:first", false );
+ isit( "#posp .seconda", "#posp a:last", true );
+ isit( "#posp .seconda", "#posp a:gt(0)", true );
+ isit( "#posp .seconda", "#posp a:lt(5)", true );
+ isit( "#posp .seconda", "#posp a:lt(1)", false );
+
+ isit( "#posp em", "#posp a:eq(0) em", true );
+ isit( "#posp em", "#posp a:lt(1) em", true );
+ isit( "#posp em", "#posp a:gt(1) em", false );
+ isit( "#posp em", "#posp a:first em", true );
+ isit( "#posp em", "#posp a em:last", true );
+ isit( "#posp em", "#posp a em:eq(2)", false );
+
+ html.remove();
+});
+
test("index()", function() {
expect( 2 );