diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2013-02-18 23:52:29 -0500 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2013-02-22 20:33:00 -0500 |
commit | 1f765366507102ea64b61052d8072205fa7f5ac3 (patch) | |
tree | 34f6d16af72ae89af8abec94a4822b99bc06350c /test/unit/event.js | |
parent | dbf3056b250bbc279fa947031181f9e25a40bacf (diff) | |
download | jquery-1f765366507102ea64b61052d8072205fa7f5ac3.tar.gz jquery-1f765366507102ea64b61052d8072205fa7f5ac3.zip |
No ticket: Revise unit tests in anticipation of Sizzle-free builds
(cherry picked from commit 59f5adb622dd6bc3419bbaa9cc2d4acd7a0b08b9)
Diffstat (limited to 'test/unit/event.js')
-rw-r--r-- | test/unit/event.js | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/test/unit/event.js b/test/unit/event.js index c3239f902..f08f5141e 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -310,8 +310,10 @@ test("bind/one/unbind(Object)", function(){ test("on/off(Object), delegate/undelegate(String, Object)", function() { expect(6); - var clickCounter = 0, mouseoverCounter = 0, - $p = jQuery("#firstp"), $a = $p.find("a:first"); + var clickCounter = 0, + mouseoverCounter = 0, + $p = jQuery("#firstp"), + $a = $p.find("a").eq(0); var events = { "click": function( event ) { @@ -326,7 +328,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() { $a.trigger("click").trigger("mouseover"); } - jQuery( document ).on( events, "#firstp a:first" ); + jQuery( document ).on( events, "#firstp a" ); $p.delegate( "a", events, 2 ); trigger(); @@ -339,7 +341,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() { equal( clickCounter, 4, "undelegate" ); equal( mouseoverCounter, 4, "undelegate" ); - jQuery( document ).off( events, "#firstp a:first" ); + jQuery( document ).off( events, "#firstp a" ); trigger(); equal( clickCounter, 4, "off" ); @@ -349,19 +351,21 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() { test("on/delegate immediate propagation", function() { expect(2); - var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick; + var lastClick, + $p = jQuery("#firstp"), + $a = $p.find("a").eq(0); lastClick = ""; - jQuery( document ).on( "click", "#firstp a:first", function(e) { + jQuery( document ).on( "click", "#firstp a", function(e) { lastClick = "click1"; e.stopImmediatePropagation(); }); - jQuery( document ).on( "click", "#firstp a:first", function(e) { + jQuery( document ).on( "click", "#firstp a", function(e) { lastClick = "click2"; }); $a.trigger( "click" ); equal( lastClick, "click1", "on stopImmediatePropagation" ); - jQuery( document ).off( "click", "#firstp a:first" ); + jQuery( document ).off( "click", "#firstp a" ); lastClick = ""; $p.delegate( "a", "click", function(e) { @@ -490,7 +494,7 @@ test("bind(), namespaced events, cloned events", 18, function() { // Make sure events stick with appendTo'd elements (which are cloned) #2027 jQuery("<a href='#fail' class='test'>test</a>").on( "click", function(){ return false; }).appendTo("#qunit-fixture"); - ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); + ok( jQuery("a.test").eq(0).triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); }); test("bind(), multi-namespaced events", function() { @@ -996,7 +1000,7 @@ test("trigger(type, [data], [fn])", function() { var pass = true, elem2; try { - elem2 = jQuery("#form input:first"); + elem2 = jQuery("#form input").eq(0); elem2.get(0).style.display = "none"; elem2.trigger("focus"); } catch(e) { @@ -1006,7 +1010,7 @@ test("trigger(type, [data], [fn])", function() { pass = true; try { - jQuery("#qunit-fixture table:first").bind("test:test", function(){}).trigger("test:test"); + jQuery("#qunit-fixture table").eq(0).bind("test:test", function(){}).trigger("test:test"); } catch (e) { pass = false; } @@ -1772,10 +1776,24 @@ test("jQuery.off using dispatched jQuery.Event", function() { test( "delegated event with delegateTarget-relative selector", function() { expect(3); - var markup = jQuery("<ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul>").appendTo("#qunit-fixture"); + var markup = jQuery("<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>").appendTo("#qunit-fixture"); + + // Non-positional selector (#12383) + markup.find("#ul0") + .on( "click", "div li a", function() { + ok( false, "div is ABOVE the delegation point!" ); + }) + .on( "click", "ul a", function() { + ok( false, "ul IS the delegation point!" ); + }) + .on( "click", "li.test a", function() { + ok( true, "li.test is below the delegation point." ); + }) + .find("#a0_0").trigger("click").end() + .off("click"); // Positional selector (#11315) - markup + markup.find("ul").eq(0) .on( "click", ">li>a", function() { ok( this.id === "a0", "child li was clicked" ); }) @@ -1787,21 +1805,6 @@ test( "delegated event with delegateTarget-relative selector", function() { .find("a").trigger("click").end() .find("#ul0").off(); - // Non-positional selector (#12383) - markup = markup.wrap("<div />").parent(); - markup - .find("#ul0") - .on( "click", "div li a", function() { - ok( false, "div is ABOVE the delegation point!" ); - }) - .on( "click", "ul a", function() { - ok( false, "ul is the delegation point!" ); - }) - .on( "click", "li.test a", function() { - ok( true, "li.test is below the delegation point." ); - }) - .find("#a0_0").trigger("click"); - markup.remove(); }); @@ -2624,12 +2627,12 @@ test( "make sure events cloned correctly", 18, function() { clone = fixture.clone( true ); - clone.find("p:first").trigger( "click", true ); // 3 events should fire + clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire clone.find("#check1").trigger( "change", true ); // 3 events should fire clone.remove(); clone = fixture.clone( true, true ); - clone.find("p:first").trigger( "click", true ); // 3 events should fire + clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire clone.find("#check1").trigger( "change", true ); // 3 events should fire fixture.off(); @@ -2639,11 +2642,11 @@ test( "make sure events cloned correctly", 18, function() { p.trigger("click"); // 0 should be fired checkbox.trigger("change"); // 0 should be fired - clone.find("p:first").trigger( "click", true ); // 3 events should fire + clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire clone.find("#check1").trigger( "change", true ); // 3 events should fire clone.remove(); - clone.find("p:first").trigger("click"); // 0 should be fired + clone.find("p").eq(0).trigger("click"); // 0 should be fired clone.find("#check1").trigger("change"); // 0 events should fire }); |