X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=1e40e0f3e6024cfb2c74d57d78c11e0ae57acfb6;hb=7705c35b140f378e407c196599cc738bc54c5cec;hp=21ed63166e11abb9182bd5a1448c1a49419cc01c;hpb=4490f4285cc4cdafba67fee726d3eba4a3d81a0f;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index 21ed631..1e40e0f 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -361,9 +361,7 @@ test("bind(), trigger change on select", function() { }).trigger('change'); }); -test("bind(), namespaced events, cloned events", function() { - expect(6); - +test("bind(), namespaced events, cloned events", 18, function() { var firstp = jQuery( "#firstp" ); firstp.bind("custom.test",function(e){ @@ -372,22 +370,31 @@ test("bind(), namespaced events, cloned events", function() { firstp.bind("click",function(e){ ok(true, "Normal click triggered"); + equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" ); }); firstp.bind("click.test",function(e){ + var check = "click"; ok( true, "Namespaced click triggered" ); + if ( e.namespace ) { + check += "test"; + } + equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" ); }); - // Trigger both bound fn (2) + //clone(true) element to verify events are cloned correctly + firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) ); + + // Trigger both bound fn (8) firstp.trigger("click"); - // Trigger one bound fn (1) + // Trigger one bound fn (4) firstp.trigger("click.test"); // Remove only the one fn firstp.unbind("click.test"); - // Trigger the remaining fn (1) + // Trigger the remaining fn (4) firstp.trigger("click"); // Remove the remaining namespaced fn @@ -402,7 +409,7 @@ test("bind(), namespaced events, cloned events", function() { }).trigger("tester"); // Make sure events stick with appendTo'd elements (which are cloned) #2027 - jQuery("test").click(function(){ return false; }).appendTo("p"); + jQuery("test").click(function(){ return false; }).appendTo("#main"); ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); }); @@ -608,18 +615,18 @@ test("unbind(type)", function() { message = "unbind many with function"; $elem.bind('error1 error2',error) - .unbind('error1 error2', error ) - .trigger('error1').triggerHandler('error2'); + .unbind('error1 error2', error ) + .trigger('error1').triggerHandler('error2'); message = "unbind many"; // #3538 $elem.bind('error1 error2',error) - .unbind('error1 error2') - .trigger('error1').triggerHandler('error2'); + .unbind('error1 error2') + .trigger('error1').triggerHandler('error2'); message = "unbind without a type or handler"; $elem.bind("error1 error2.test",error) - .unbind() - .trigger("error1").triggerHandler("error2"); + .unbind() + .trigger("error1").triggerHandler("error2"); }); test("unbind(eventObject)", function() { @@ -676,6 +683,20 @@ test("hover()", function() { equals( times, 4, "hover handlers fired" ); }); +test("mouseover triggers mouseenter", function() { + expect(1); + + var count = 0, + elem = jQuery(""); + elem.mouseenter(function () { + count++; + }); + elem.trigger('mouseover'); + equals(count, 1, "make sure mouseover triggers a mouseenter" ); + + elem.remove(); +}); + test("trigger() shortcuts", function() { expect(6); @@ -1448,6 +1469,8 @@ test("live with change", function(){ }); test("live with submit", function() { + expect(5); + var count1 = 0, count2 = 0; jQuery("#testForm").live("submit", function(ev) { @@ -1464,7 +1487,16 @@ test("live with submit", function() { equals( count1, 1, "Verify form submit." ); equals( count2, 1, "Verify body submit." ); + jQuery("#testForm input[name=sub1]").live("click", function(ev) { + ok( true, "cancelling submit still calls click handler" ); + }); + + jQuery("#testForm input[name=sub1]")[0].click(); + equals( count1, 2, "Verify form submit." ); + equals( count2, 2, "Verify body submit." ); + jQuery("#testForm").die("submit"); + jQuery("#testForm input[name=sub1]").die("click"); jQuery("body").die("submit"); }); @@ -1948,6 +1980,31 @@ test("window resize", function() { ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." ); }); +test("focusin bubbles", function() { + expect(4); + + var input = jQuery( '' ).prependTo( "body" ), + order = 0; + + jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){ + equals( 1, order++, "focusin on the body second" ); + }); + + input.bind( "focusin.focusinBubblesTest", function(){ + equals( 0, order++, "focusin on the element first" ); + }); + + // DOM focus method + input[0].focus(); + // jQuery trigger, which calls DOM focus + order = 0; + input[0].blur(); + input.trigger( "focus" ); + + input.remove(); + jQuery( "body" ).unbind( "focusin.focusinBubblesTest" ); +}); + /* test("jQuery(function($) {})", function() { stop();