@@ -403,6 +403,54 @@ export function main() {
403403 } ) ;
404404 } ) ;
405405
406+ describe ( 'event handlers' , ( ) => {
407+ var view , ctx , called ;
408+
409+ function createViewAndContext ( protoView ) {
410+ view = createView ( protoView ) ;
411+ ctx = view . context ;
412+ called = 0 ;
413+ ctx . callMe = ( ) => called += 1 ;
414+ }
415+
416+ function dispatchClick ( el ) {
417+ DOM . dispatchEvent ( el , DOM . createMouseEvent ( 'click' ) ) ;
418+ }
419+
420+ function createProtoView ( ) {
421+ var pv = new ProtoView ( el ( '<div class="ng-binding"><div></div></div>' ) ,
422+ new ProtoRecordRange ( ) ) ;
423+ pv . bindElement ( new TestProtoElementInjector ( null , 0 , [ ] ) ) ;
424+ pv . bindEvent ( 'click' , parser . parseBinding ( 'callMe()' , null ) ) ;
425+ return pv ;
426+ }
427+
428+ it ( 'should fire on non-bubbling native events' , ( ) => {
429+ createViewAndContext ( createProtoView ( ) ) ;
430+
431+ dispatchClick ( view . nodes [ 0 ] ) ;
432+
433+ expect ( called ) . toEqual ( 1 ) ;
434+ } ) ;
435+
436+ it ( 'should not fire on a bubbled native events' , ( ) => {
437+ createViewAndContext ( createProtoView ( ) ) ;
438+
439+ dispatchClick ( view . nodes [ 0 ] . firstChild ) ;
440+
441+ // This test passes trivially on webkit browsers due to
442+ // https://bugs.webkit.org/show_bug.cgi?id=122755
443+ expect ( called ) . toEqual ( 0 ) ;
444+ } ) ;
445+
446+ it ( 'should not throw if the view is dehydrated' , ( ) => {
447+ createViewAndContext ( createProtoView ( ) ) ;
448+
449+ view . dehydrate ( ) ;
450+ dispatchClick ( view . nodes [ 0 ] ) ;
451+ } ) ;
452+ } ) ;
453+
406454 describe ( 'react to record changes' , ( ) => {
407455 var view , cd , ctx ;
408456
@@ -583,6 +631,7 @@ class MyEvaluationContext {
583631 foo :string ;
584632 a ;
585633 b ;
634+ callMe ;
586635 constructor ( ) {
587636 this . foo = 'bar' ;
588637 } ;
0 commit comments