X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=d324432767ea0dba58bddccb5676f6efdfab53aa;hb=811891785f5bfa3f42ec9cb18e68fc3a114935e9;hp=98833ece87d9267fb025ae840a92be19467b7972;hpb=8f042d8be34fe2d197e45d6fa398456759a4c007;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index 98833ec..d324432 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -162,6 +162,25 @@ test("bind(), multi-namespaced events", function() { jQuery("#firstp").trigger("custom"); }); +test("bind(), with different this object", function() { + expect(4); + var thisObject = { myThis: true }, + data = { myData: true }, + handler1 = function( event ) { + equals( this, thisObject, "bind() with different this object" ); + }, + handler2 = function( event ) { + equals( this, thisObject, "bind() with different this object and data" ); + equals( event.data, data, "bind() with different this object and data" ); + }; + + jQuery("#firstp") + .bind("click", handler1, thisObject).click().unbind("click", handler1) + .bind("click", data, handler2, thisObject).click().unbind("click", handler2); + + ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." ); +}); + test("unbind(type)", function() { expect( 0 ); @@ -508,7 +527,7 @@ test("toggle(Function, Function, ...)", function() { }); test(".live()/.die()", function() { - expect(54); + expect(58); var submit = 0, div = 0, livea = 0, liveb = 0; @@ -605,6 +624,18 @@ test(".live()/.die()", function() { jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); }); jQuery("#foo").trigger("click", true).die("click"); + // Test binding with different this object + jQuery("#foo").live("click", function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" }); + jQuery("#foo").trigger("click").die("click"); + + // Test binding with different this object, event data, and trigger data + jQuery("#foo").live("click", true, function(e, data){ + equals( e.data, true, "live with with different this object, event data, and trigger data" ); + equals( this.foo, "bar", "live with with different this object, event data, and trigger data" ); + equals( data, true, "live with with different this object, event data, and trigger data") + }, { foo: "bar" }); + jQuery("#foo").trigger("click", true).die("click"); + // Verify that return false prevents default action jQuery("#anchor2").live("click", function(){ return false; }); var hash = window.location.hash;