Make it so that you can pass in event data to .click(), et. al. Fixes #6187.
[jquery.git] / test / unit / event.js
index cbde90e..6404900 100644 (file)
@@ -11,6 +11,17 @@ test("bind(), with data", function() {
        ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
 });
 
+test("click(), with data", function() {
+       expect(3);
+       var handler = function(event) {
+               ok( event.data, "bind() with data, check passed data exists" );
+               equals( event.data.foo, "bar", "bind() with data, Check value of passed data" );
+       };
+       jQuery("#firstp").click({foo: "bar"}, handler).click().unbind("click", handler);
+
+       ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
+});
+
 test("bind(), with data, trigger with data", function() {
        expect(4);
        var handler = function(event, data) {
@@ -373,6 +384,35 @@ test("bind(), with different this object", function() {
        ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
 });
 
+test("bind()/trigger()/unbind() on plain object", function() {
+       expect( 2 );
+
+       var obj = {};
+
+       // Make sure it doesn't complain when no events are found
+       jQuery(obj).trigger("test");
+
+       // Make sure it doesn't complain when no events are found
+       jQuery(obj).unbind("test");
+
+       jQuery(obj).bind("test", function(){
+               ok( true, "Custom event run." );
+       });
+
+       ok( jQuery(obj).data("events"), "Object has events bound." );
+
+       // Should trigger 1
+       jQuery(obj).trigger("test");
+
+       jQuery(obj).unbind("test");
+
+       // Should trigger 0
+       jQuery(obj).trigger("test");
+
+       // Make sure it doesn't complain when no events are found
+       jQuery(obj).unbind("test");
+});
+
 test("unbind(type)", function() {
        expect( 0 );