X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent%2FeventTest.js;h=cacfdeb666f25006e3eb083961fe8984a361d004;hb=456f0fe5985eaad42eba456b9ff710771669607c;hp=84c7b97d9f59fd96e5dab42e23a993d6cb8c224c;hpb=042a46386a4e5efe787f963245aa534663559838;p=jquery.git diff --git a/src/event/eventTest.js b/src/event/eventTest.js index 84c7b97..cacfdeb 100644 --- a/src/event/eventTest.js +++ b/src/event/eventTest.js @@ -1,7 +1,7 @@ module("event"); test("bind()", function() { - expect(11); + expect(15); var handler = function(event) { ok( event.data, "bind() with data, check passed data exists" ); @@ -45,6 +45,28 @@ test("bind()", function() { $("select").each(function(i){ $(this).bind('change', i, selectOnChange); }).trigger('change'); + + reset(); + + $("#firstp").bind("click",function(e){ + ok(true, "Normal click triggered"); + }); + + $("#firstp").bind("click.test",function(e){ + ok(true, "Namespaced click triggered"); + }); + + // Trigger both bound fn (2) + $("#firstp").trigger("click"); + + // Trigger one bound fn (1) + $("#firstp").trigger("click.test"); + + // Remove only the one fn + $("#firstp").unbind("click.test"); + + // Trigger the remaining fn (1) + $("#firstp").trigger("click"); }); test("click()", function() { @@ -93,8 +115,8 @@ test("unbind(event)", function() { ok( !el[0].$events, "Removed the events expando after all handlers are unbound." ); }); -test("trigger(event, [data]", function() { - expect(28); +test("trigger(event, [data], [fn])", function() { + expect(40); var handler = function(event, a, b, c) { equals( event.type, "click", "check passed data" ); @@ -104,6 +126,13 @@ test("trigger(event, [data]", function() { return "test"; }; + var handler2 = function(a, b, c) { + equals( a, 1, "check passed data" ); + equals( b, "2", "check passed data" ); + equals( c, "abc", "check passed data" ); + return "test2"; + }; + // Simulate a "native" click $("#firstp")[0].click = function(){ ok( true, "Native call was triggered" ); @@ -114,8 +143,8 @@ test("trigger(event, [data]", function() { $("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]); // Triggers handlers, native, and extra fn - // Triggers 9 - $("#firstp").trigger("click", [1, "2", "abc"], handler); + // Triggers 8 + $("#firstp").trigger("click", [1, "2", "abc"], handler2); // Simulate a "native" click $("#firstp")[0].click = function(){ @@ -123,12 +152,23 @@ test("trigger(event, [data]", function() { }; // Trigger only the handlers (no native) - // Triggers 4 + // Triggers 5 equals( $("#firstp").triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" ); // Trigger only the handlers (no native) and extra fn // Triggers 8 - equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler), "test", "Verify handler response" ); + equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler2), "test", "Verify handler response" ); + + // Build fake click event to pass in + var eventObj = jQuery.event.fix({ type: "click", target: document.body }); + + // Trigger only the handlers (no native), with external event obj + // Triggers 5 + equals( $("#firstp").triggerHandler("foo", [eventObj, 1, "2", "abc"]), "test", "Verify handler response" ); + + // Trigger only the handlers (no native) and extra fn, with external event obj + // Triggers 9 + equals( $("#firstp").triggerHandler("foo", [eventObj, 1, "2", "abc"], handler), "test", "Verify handler response" ); }); test("toggle(Function, Function)", function() {