Fix some whitespace issues.
[jquery.git] / test / unit / event.js
index 21ed631..b7b2604 100644 (file)
@@ -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("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
+       jQuery("<a href='#fail' class='test'>test</a>").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() {
@@ -1448,6 +1455,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 +1473,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");
 });