unit tests for using jQuery events on non-dom elements. fixes #3439. thanks morgan
[jquery.git] / test / unit / event.js
1 module("event");
2
3 test("bind(), with data", function() {
4         expect(3);
5         var handler = function(event) {
6                 ok( event.data, "bind() with data, check passed data exists" );
7                 equals( event.data.foo, "bar", "bind() with data, Check value of passed data" );
8         };
9         jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
10
11         ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
12 });
13
14 test("bind(), with data, trigger with data", function() {
15         expect(4);
16         var handler = function(event, data) {
17                 ok( event.data, "check passed data exists" );
18                 equals( event.data.foo, "bar", "Check value of passed data" );
19                 ok( data, "Check trigger data" );
20                 equals( data.bar, "foo", "Check value of trigger data" );
21         };
22         jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
23 });
24
25 test("bind(), multiple events at once", function() {
26         expect(2);
27         var clickCounter = 0,
28                 mouseoverCounter = 0;
29         var handler = function(event) {
30                 if (event.type == "click")
31                         clickCounter += 1;
32                 else if (event.type == "mouseover")
33                         mouseoverCounter += 1;
34         };
35         jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
36         equals( clickCounter, 1, "bind() with multiple events at once" );
37         equals( mouseoverCounter, 1, "bind() with multiple events at once" );
38 });
39
40 test("bind(), no data", function() {
41         expect(1);
42         var handler = function(event) {
43                 ok ( !event.data, "Check that no data is added to the event object" );
44         };
45         jQuery("#firstp").bind("click", handler).trigger("click");
46 });
47
48 test("bind(), iframes", function() {
49         // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
50         var doc = jQuery("#loadediframe").contents();
51         
52         jQuery("div", doc).bind("click", function() {
53                 ok( true, "Binding to element inside iframe" );
54         }).click().unbind('click');
55 });
56
57 test("bind(), trigger change on select", function() {
58         expect(3);
59         var counter = 0;
60         function selectOnChange(event) {
61                 equals( event.data, counter++, "Event.data is not a global event object" );
62         };
63         jQuery("#form select").each(function(i){
64                 jQuery(this).bind('change', i, selectOnChange);
65         }).trigger('change');
66 });
67
68 test("bind(), namespaced events, cloned events", function() {
69         expect(6);
70
71         jQuery("#firstp").bind("custom.test",function(e){
72                 ok(true, "Custom event triggered");
73         });
74
75         jQuery("#firstp").bind("click",function(e){
76                 ok(true, "Normal click triggered");
77         });
78
79         jQuery("#firstp").bind("click.test",function(e){
80                 ok(true, "Namespaced click triggered");
81         });
82
83         // Trigger both bound fn (2)
84         jQuery("#firstp").trigger("click");
85
86         // Trigger one bound fn (1)
87         jQuery("#firstp").trigger("click.test");
88
89         // Remove only the one fn
90         jQuery("#firstp").unbind("click.test");
91
92         // Trigger the remaining fn (1)
93         jQuery("#firstp").trigger("click");
94
95         // Remove the remaining fn
96         jQuery("#firstp").unbind(".test");
97
98         // Trigger the remaining fn (0)
99         jQuery("#firstp").trigger("custom");
100
101         // using contents will get comments regular, text, and comment nodes
102         jQuery("#nonnodes").contents().bind("tester", function () {
103                 equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
104         }).trigger("tester");
105
106         // Make sure events stick with appendTo'd elements (which are cloned) #2027
107         jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
108         ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
109 });
110
111 test("bind(), multi-namespaced events", function() {
112         expect(6);
113         
114         var order = [
115                 "click.test.abc",
116                 "click.test.abc",
117                 "click.test",
118                 "click.test.abc",
119                 "click.test",
120                 "custom.test2"
121         ];
122         
123         function check(name, msg){
124                 same(name, order.shift(), msg);
125         }
126
127         jQuery("#firstp").bind("custom.test",function(e){
128                 check("custom.test", "Custom event triggered");
129         });
130
131         jQuery("#firstp").bind("custom.test2",function(e){
132                 check("custom.test2", "Custom event triggered");
133         });
134
135         jQuery("#firstp").bind("click.test",function(e){
136                 check("click.test", "Normal click triggered");
137         });
138
139         jQuery("#firstp").bind("click.test.abc",function(e){
140                 check("click.test.abc", "Namespaced click triggered");
141         });
142
143         // Trigger both bound fn (1)
144         jQuery("#firstp").trigger("click.test.abc");
145
146         // Trigger one bound fn (1)
147         jQuery("#firstp").trigger("click.abc");
148
149         // Trigger two bound fn (2)
150         jQuery("#firstp").trigger("click.test");
151
152         // Remove only the one fn
153         jQuery("#firstp").unbind("click.abc");
154
155         // Trigger the remaining fn (1)
156         jQuery("#firstp").trigger("click");
157
158         // Remove the remaining fn
159         jQuery("#firstp").unbind(".test");
160
161         // Trigger the remaining fn (1)
162         jQuery("#firstp").trigger("custom");
163 });
164
165 test("unbind(type)", function() {
166         expect( 0 );
167         
168         var $elem = jQuery("#firstp"),
169                 message;
170
171         function error(){
172                 ok( false, message );
173         }
174         
175         message = "unbind passing function";
176         $elem.bind('error', error).unbind('error',error).triggerHandler('error');
177         
178         message = "unbind all from event";
179         $elem.bind('error', error).unbind('error').triggerHandler('error');
180         
181         message = "unbind all";
182         $elem.bind('error', error).unbind().triggerHandler('error');
183         
184         message = "unbind many with function";
185         $elem.bind('error error2',error)
186                  .unbind('error error2', error )
187                  .trigger('error').triggerHandler('error2');
188
189         message = "unbind many"; // #3538
190         $elem.bind('error error2',error)
191                  .unbind('error error2')
192                  .trigger('error').triggerHandler('error2');
193         
194         message = "unbind without a type or handler";
195         $elem.bind("error error2.test",error)
196                  .unbind()
197                  .trigger("error").triggerHandler("error2");
198 });
199
200 test("unbind(eventObject)", function() {
201         expect(4);
202         
203         var $elem = jQuery("#firstp"),
204                 num;
205
206         function assert( expected ){
207                 num = 0;
208                 $elem.trigger('foo').triggerHandler('bar');
209                 equals( num, expected, "Check the right handlers are triggered" );
210         }
211         
212         $elem
213                 // This handler shouldn't be unbound
214                 .bind('foo', function(){
215                         num += 1;
216                 })
217                 .bind('foo', function(e){
218                         $elem.unbind( e )
219                         num += 2;
220                 })
221                 // Neither this one
222                 .bind('bar', function(){
223                         num += 4;
224                 });
225                 
226         assert( 7 );
227         assert( 5 );
228         
229         $elem.unbind('bar');
230         assert( 1 );
231         
232         $elem.unbind(); 
233         assert( 0 );
234 });
235
236 test("trigger() shortcuts", function() {
237         expect(6);
238         jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
239                 var close = jQuery('spanx', this); // same with jQuery(this).find('span');
240                 equals( close.length, 0, "Context element does not exist, length must be zero" );
241                 ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
242                 return false;
243         }).click();
244         
245         jQuery("#check1").click(function() {
246                 ok( true, "click event handler for checkbox gets fired twice, see #815" );
247         }).click();
248         
249         var counter = 0;
250         jQuery('#firstp')[0].onclick = function(event) {
251                 counter++;
252         };
253         jQuery('#firstp').click();
254         equals( counter, 1, "Check that click, triggers onclick event handler also" );
255         
256         var clickCounter = 0;
257         jQuery('#simon1')[0].onclick = function(event) {
258                 clickCounter++;
259         };
260         jQuery('#simon1').click();
261         equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
262         
263         jQuery('<img />').load(function(){
264                 ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
265         }).load();
266 });
267
268 test("trigger() bubbling", function() {
269         expect(14);
270
271         var doc = 0, html = 0, body = 0, main = 0, ap = 0;
272
273         jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
274         jQuery("html").bind("click", function(e){ html++; });
275         jQuery("body").bind("click", function(e){ body++; });
276         jQuery("#main").bind("click", function(e){ main++; });
277         jQuery("#ap").bind("click", function(){ ap++; return false; });
278
279         jQuery("html").trigger("click");
280         equals( doc, 1, "HTML bubble" );
281         equals( html, 1, "HTML bubble" );
282
283         jQuery("body").trigger("click");
284         equals( doc, 2, "Body bubble" );
285         equals( html, 2, "Body bubble" );
286         equals( body, 1, "Body bubble" );
287
288         jQuery("#main").trigger("click");
289         equals( doc, 3, "Main bubble" );
290         equals( html, 3, "Main bubble" );
291         equals( body, 2, "Main bubble" );
292         equals( main, 1, "Main bubble" );
293
294         jQuery("#ap").trigger("click");
295         equals( doc, 3, "ap bubble" );
296         equals( html, 3, "ap bubble" );
297         equals( body, 2, "ap bubble" );
298         equals( main, 1, "ap bubble" );
299         equals( ap, 1, "ap bubble" );
300 });
301
302 test("trigger(type, [data], [fn])", function() {
303         expect(11);
304
305         var handler = function(event, a, b, c) {
306                 equals( event.type, "click", "check passed data" );
307                 equals( a, 1, "check passed data" );
308                 equals( b, "2", "check passed data" );
309                 equals( c, "abc", "check passed data" );
310                 return "test";
311         };
312
313         var $elem = jQuery("#firstp");
314
315         // Simulate a "native" click
316         $elem[0].click = function(){
317                 ok( true, "Native call was triggered" );
318         };
319
320         // Triggers handlrs and native
321         // Trigger 5
322         $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
323
324         // Simulate a "native" click
325         $elem[0].click = function(){
326                 ok( false, "Native call was triggered" );
327         };
328
329         // Trigger only the handlers (no native)
330         // Triggers 5
331         equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
332
333         var pass = true;
334         try {
335                 jQuery('#form input:first').hide().trigger('focus');
336         } catch(e) {
337                 pass = false;
338         }
339         ok( pass, "Trigger focus on hidden element" );
340 });
341
342 test("trigger(eventObject, [data], [fn])", function() {
343         expect(25);
344         
345         var $parent = jQuery('<div id="par" />').hide().appendTo('body'),
346                 $child = jQuery('<p id="child">foo</p>').appendTo( $parent );
347         
348         var event = jQuery.Event("noNew");      
349         ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
350         equals( event.type, "noNew", "Verify its type" );
351         
352         equals( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
353         equals( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
354         equals( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
355         
356         event.preventDefault();
357         equals( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
358         event.stopPropagation();
359         equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
360         
361         event.isPropagationStopped = function(){ return false };
362         event.stopImmediatePropagation();
363         equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
364         equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
365         
366         $parent.bind('foo',function(e){
367                 // Tries bubbling
368                 equals( e.type, 'foo', 'Verify event type when passed passing an event object' );
369                 equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' );
370                 equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' );
371                 equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' );
372         });
373         
374         // test with an event object
375         event = new jQuery.Event("foo");
376         event.secret = 'boo!';
377         $child.trigger(event);
378         
379         // test with a literal object
380         $child.trigger({type:'foo', secret:'boo!'});
381         
382         $parent.unbind();
383
384         function error(){
385                 ok( false, "This assertion shouldn't be reached");
386         }
387         
388         $parent.bind('foo', error );
389         
390         $child.bind('foo',function(e, a, b, c ){
391                 equals( arguments.length, 4, "Check arguments length");
392                 equals( a, 1, "Check first custom argument");
393                 equals( b, 2, "Check second custom argument");
394                 equals( c, 3, "Check third custom argument");
395                 
396                 equals( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
397                 equals( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
398                 equals( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
399                 
400                 // Skips both errors
401                 e.stopImmediatePropagation();
402                 
403                 return "result";
404         });
405         
406         // We should add this back in when we want to test the order
407         // in which event handlers are iterated.
408         //$child.bind('foo', error );
409         
410         event = new jQuery.Event("foo");
411         $child.trigger( event, [1,2,3] ).unbind();
412         equals( event.result, "result", "Check event.result attribute");
413         
414         // Will error if it bubbles
415         $child.triggerHandler('foo');
416         
417         $child.unbind();
418         $parent.unbind().remove();
419 });
420
421 test("jQuery.Event.currentTarget", function(){
422         expect(1);
423         
424         var counter = 0,
425                 $elem = jQuery('<button>a</button>').click(function(e){
426                 equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
427         });
428         
429         // Fake event
430         $elem.trigger('click');
431         
432         // Cleanup
433         $elem.unbind();
434 });
435
436 test("toggle(Function, Function, ...)", function() {
437         expect(11);
438         
439         var count = 0,
440                 fn1 = function(e) { count++; },
441                 fn2 = function(e) { count--; },
442                 preventDefault = function(e) { e.preventDefault() },
443                 link = jQuery('#mark');
444         link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
445         equals( count, 1, "Check for toggle(fn, fn)" );
446
447         jQuery("#firstp").toggle(function () {
448                 equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
449         }, function() {}).trigger("click", [ 1, 2, 3 ]);
450
451         var first = 0;
452         jQuery("#simon1").one("click", function() {
453                 ok( true, "Execute event only once" );
454                 jQuery(this).toggle(function() {
455                         equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
456                 }, function() {
457                         equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
458                 });
459                 return false;
460         }).click().click().click();
461         
462         var turn = 0;
463         var fns = [
464                 function(){
465                         turn = 1;
466                 },
467                 function(){
468                         turn = 2;
469                 },
470                 function(){
471                         turn = 3;
472                 }
473         ];
474         
475         var $div = jQuery("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] );
476         $div.click();
477         equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
478         $div.click();
479         equals( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
480         $div.click();
481         equals( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
482         $div.click();
483         equals( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
484         $div.click();
485         equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
486         
487         $div.unbind('click',fns[0]);
488         var data = jQuery.data( $div[0], 'events' );
489         ok( !data, "Unbinding one function from toggle unbinds them all");
490 });
491
492 test(".live()/.die()", function() {
493         expect(54);
494
495         var submit = 0, div = 0, livea = 0, liveb = 0;
496
497         jQuery("div").live("submit", function(){ submit++; return false; });
498         jQuery("div").live("click", function(){ div++; });
499         jQuery("div#nothiddendiv").live("click", function(){ livea++; });
500         jQuery("div#nothiddendivchild").live("click", function(){ liveb++; });
501
502         // Nothing should trigger on the body
503         jQuery("body").trigger("click");
504         equals( submit, 0, "Click on body" );
505         equals( div, 0, "Click on body" );
506         equals( livea, 0, "Click on body" );
507         equals( liveb, 0, "Click on body" );
508
509         // This should trigger two events
510         jQuery("div#nothiddendiv").trigger("click");
511         equals( submit, 0, "Click on div" );
512         equals( div, 1, "Click on div" );
513         equals( livea, 1, "Click on div" );
514         equals( liveb, 0, "Click on div" );
515
516         // This should trigger three events (w/ bubbling)
517         jQuery("div#nothiddendivchild").trigger("click");
518         equals( submit, 0, "Click on inner div" );
519         equals( div, 2, "Click on inner div" );
520         equals( livea, 2, "Click on inner div" );
521         equals( liveb, 1, "Click on inner div" );
522
523         // This should trigger one submit
524         jQuery("div#nothiddendivchild").trigger("submit");
525         equals( submit, 1, "Submit on div" );
526         equals( div, 2, "Submit on div" );
527         equals( livea, 2, "Submit on div" );
528         equals( liveb, 1, "Submit on div" );
529
530         // Make sure no other events were removed in the process
531         jQuery("div#nothiddendivchild").trigger("click");
532         equals( submit, 1, "die Click on inner div" );
533         equals( div, 3, "die Click on inner div" );
534         equals( livea, 3, "die Click on inner div" );
535         equals( liveb, 2, "die Click on inner div" );
536
537         // Now make sure that the removal works
538         jQuery("div#nothiddendivchild").die("click");
539         jQuery("div#nothiddendivchild").trigger("click");
540         equals( submit, 1, "die Click on inner div" );
541         equals( div, 4, "die Click on inner div" );
542         equals( livea, 4, "die Click on inner div" );
543         equals( liveb, 2, "die Click on inner div" );
544
545         // Make sure that the click wasn't removed too early
546         jQuery("div#nothiddendiv").trigger("click");
547         equals( submit, 1, "die Click on inner div" );
548         equals( div, 5, "die Click on inner div" );
549         equals( livea, 5, "die Click on inner div" );
550         equals( liveb, 2, "die Click on inner div" );
551
552         // Make sure that stopPropgation doesn't stop live events
553         jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); });
554         jQuery("div#nothiddendivchild").trigger("click");
555         equals( submit, 1, "stopPropagation Click on inner div" );
556         equals( div, 6, "stopPropagation Click on inner div" );
557         equals( livea, 6, "stopPropagation Click on inner div" );
558         equals( liveb, 3, "stopPropagation Click on inner div" );
559
560         jQuery("div#nothiddendivchild").die("click");
561         jQuery("div#nothiddendiv").die("click");
562         jQuery("div").die("click");
563         jQuery("div").die("submit");
564
565         // Test binding with a different context
566         var clicked = 0, container = jQuery('#main')[0];
567         jQuery("#foo", container).live("click", function(e){ clicked++; });
568         jQuery("div").trigger('click');
569         jQuery("#foo").trigger('click');
570         jQuery("#main").trigger('click');
571         jQuery("body").trigger('click');
572         equals( clicked, 2, "live with a context" );
573
574         // Make sure the event is actually stored on the context
575         ok( jQuery.data(container, "events").live, "live with a context" );
576
577         // Test unbinding with a different context
578         jQuery("#foo", container).die("click");
579         jQuery("#foo").trigger('click');
580         equals( clicked, 2, "die with a context");
581
582         // Test binding with event data
583         jQuery("#foo").live("click", true, function(e){ equals( e.data, true, "live with event data" ); });
584         jQuery("#foo").trigger("click").die("click");
585
586         // Test binding with trigger data
587         jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); });
588         jQuery("#foo").trigger("click", true).die("click");
589
590         // Verify that return false prevents default action
591         jQuery("#anchor2").live("click", function(){ return false; });
592         var hash = window.location.hash;
593         jQuery("#anchor2").trigger("click");
594         equals( window.location.hash, hash, "return false worked" );
595         jQuery("#anchor2").die("click");
596
597         // Verify that .preventDefault() prevents default action
598         jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
599         var hash = window.location.hash;
600         jQuery("#anchor2").trigger("click");
601         equals( window.location.hash, hash, "e.preventDefault() worked" );
602         jQuery("#anchor2").die("click");
603
604         // Test binding the same handler to multiple points
605         var called = 0;
606         function callback(){ called++; return false; }
607
608         jQuery("#nothiddendiv").live("click", callback);
609         jQuery("#anchor2").live("click", callback);
610
611         jQuery("#nothiddendiv").trigger("click");
612         equals( called, 1, "Verify that only one click occurred." );
613
614         jQuery("#anchor2").trigger("click");
615         equals( called, 2, "Verify that only one click occurred." );
616
617         // Make sure that only one callback is removed
618         jQuery("#anchor2").die("click", callback);
619
620         jQuery("#nothiddendiv").trigger("click");
621         equals( called, 3, "Verify that only one click occurred." );
622
623         jQuery("#anchor2").trigger("click");
624         equals( called, 3, "Verify that no click occurred." );
625
626         // Make sure that it still works if the selector is the same,
627         // but the event type is different
628         jQuery("#nothiddendiv").live("foo", callback);
629
630         // Cleanup
631         jQuery("#nothiddendiv").die("click", callback);
632
633         jQuery("#nothiddendiv").trigger("click");
634         equals( called, 3, "Verify that no click occurred." );
635
636         jQuery("#nothiddendiv").trigger("foo");
637         equals( called, 4, "Verify that one foo occurred." );
638
639         // Cleanup
640         jQuery("#nothiddendiv").die("foo", callback);
641         
642         // Make sure we don't loose the target by DOM modifications
643         // after the bubble already reached the liveHandler
644         var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
645         
646         jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); });
647         jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
648         
649         jQuery("#nothiddendiv span").click();
650         equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
651         equals( livec, 1, "Verify that second handler occurred even with nuked target." );
652         
653         // Cleanup
654         jQuery("#nothiddendivchild").die("click");
655
656         // Verify that .live() ocurs and cancel buble in the same order as
657         // we would expect .bind() and .click() without delegation
658         var lived = 0, livee = 0;
659         
660         // bind one pair in one order
661         jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
662         jQuery('span#liveSpan1').live('click', function(){ livee++; });
663
664         jQuery('span#liveSpan1 a').click();
665         equals( lived, 1, "Verify that only one first handler occurred." );
666         equals( livee, 0, "Verify that second handler don't." );
667
668         // and one pair in inverse
669         jQuery('#liveHandlerOrder span#liveSpan2').live('click', function(){ livee++; });
670         jQuery('#liveHandlerOrder span#liveSpan2 a').live('click', function(){ lived++; return false; });
671
672         jQuery('span#liveSpan2 a').click();
673         equals( lived, 2, "Verify that only one first handler occurred." );
674         equals( livee, 0, "Verify that second handler don't." );
675         
676         // Cleanup
677         jQuery("span#liveSpan1 a, span#liveSpan1, span#liveSpan2 a, span#liveSpan2").die("click");
678         
679         // Test this, target and currentTarget are correct
680         jQuery('span#liveSpan1').live('click', function(e){ 
681                 equals( this.id, 'liveSpan1', 'Check the this within a live handler' );
682                 equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a live handler' );
683                 equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a live handler' );
684         });
685         
686         jQuery('span#liveSpan1 a').click();
687         
688         jQuery('span#liveSpan1').die('click');
689 });
690
691 test("Non DOM element events", function() {
692         expect(3);
693
694         jQuery({})
695                 .bind('nonelementglobal', function(e) {
696                         ok( true, "Global event on non-DOM annonymos object triggered" );
697                 });
698
699         var o = {};
700
701         jQuery(o)
702                 .bind('nonelementobj', function(e) {
703                         ok( true, "Event on non-DOM object triggered" );
704                 }).bind('nonelementglobal', function() {
705                         ok( true, "Global event on non-DOM object triggered" );
706                 });
707
708         jQuery(o).trigger('nonelementobj');
709         jQuery.event.trigger('nonelementglobal');
710 });
711
712 /*
713 test("jQuery(function($) {})", function() {
714         stop();
715         jQuery(function($) {
716                 equals(jQuery, $, "ready doesn't provide an event object, instead it provides a reference to the jQuery function, see http://docs.jquery.com/Events/ready#fn");
717                 start();
718         });
719 });
720
721 test("event properties", function() {
722         stop();
723         jQuery("#simon1").click(function(event) {
724                 ok( event.timeStamp, "assert event.timeStamp is present" );
725                 start();
726         }).click();
727 });
728 */