X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=b0cc5026dc246b1ccb6c8636ed077ae1f4f0ff4a;hb=98c7248518f9a2082ccf50240b5ab44bf98d7b5e;hp=df01baeacc5b9817ff02a029e3fbd9be5056e424;hpb=d24443fb55ddc6a309c08a9a248128fef269d2a3;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index df01bae..b0cc502 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -37,6 +37,86 @@ test("bind(), multiple events at once", function() { equals( mouseoverCounter, 1, "bind() with multiple events at once" ); }); +test("bind(), multiple events at once and namespaces", function() { + expect(7); + + var cur, obj = {}; + + var div = jQuery("
").bind("focusin.a", function(e) { + equals( e.type, cur, "Verify right single event was fired." ); + }); + + cur = "focusin"; + div.trigger("focusin.a"); + + div = jQuery("
").bind("click mouseover", obj, function(e) { + equals( e.type, cur, "Verify right multi event was fired." ); + equals( e.data, obj, "Make sure the data came in correctly." ); + }); + + cur = "click"; + div.trigger("click"); + + cur = "mouseover"; + div.trigger("mouseover"); + + div = jQuery("
").bind("focusin.a focusout.b", function(e) { + equals( e.type, cur, "Verify right multi event was fired." ); + }); + + cur = "focusin"; + div.trigger("focusin.a"); + + cur = "focusout"; + div.trigger("focusout.b"); +}); + +test("bind(), namespace with special add", function() { + expect(18); + + var div = jQuery("
").bind("test", function(e) { + ok( true, "Test event fired." ); + }); + + var i = 0; + + jQuery.event.special.test = { + _default: function(e) { + equals( this, document, "Make sure we're at the top of the chain." ); + equals( e.type, "test", "And that we're still dealing with a test event." ); + equals( e.target, div[0], "And that the target is correct." ); + }, + setup: function(){}, + teardown: function(){}, + add: function( handler, data, namespaces ) { + return function(e) { + e.xyz = ++i; + handler.apply( this, arguments ); + }; + }, + remove: function() {} + }; + + div.bind("test.a", {x: 1}, function(e) { + ok( !!e.xyz, "Make sure that the data is getting passed through." ); + equals( e.data.x, 1, "Make sure data is attached properly." ); + }); + + div.bind("test.b", {x: 2}, function(e) { + ok( !!e.xyz, "Make sure that the data is getting passed through." ); + equals( e.data.x, 2, "Make sure data is attached properly." ); + }); + + // Should trigger 5 + div.trigger("test"); + + // Should trigger 2 + div.trigger("test.a"); + + // Should trigger 2 + div.trigger("test.b"); +}); + test("bind(), no data", function() { expect(1); var handler = function(event) {