@@ -591,6 +591,23 @@ export function main() {
591591 } ) ;
592592 } ) ) ;
593593
594+ it ( 'should support preventing default on render events' , inject ( [ TestBed , AsyncTestCompleter ] , ( tb , async ) => {
595+ tb . overrideView ( MyComp , new View ( {
596+ template : '<input type="checkbox" listenerprevent></input><input type="checkbox" listenernoprevent></input>' ,
597+ directives : [ DecoratorListeningDomEventPrevent , DecoratorListeningDomEventNoPrevent ]
598+ } ) ) ;
599+
600+ tb . createView ( MyComp , { context : ctx } ) . then ( ( view ) => {
601+ expect ( DOM . getChecked ( view . rootNodes [ 0 ] ) ) . toBeFalsy ( ) ;
602+ expect ( DOM . getChecked ( view . rootNodes [ 1 ] ) ) . toBeFalsy ( ) ;
603+ DOM . dispatchEvent ( view . rootNodes [ 0 ] , DOM . createMouseEvent ( 'click' ) ) ;
604+ DOM . dispatchEvent ( view . rootNodes [ 1 ] , DOM . createMouseEvent ( 'click' ) ) ;
605+ expect ( DOM . getChecked ( view . rootNodes [ 0 ] ) ) . toBeFalsy ( ) ;
606+ expect ( DOM . getChecked ( view . rootNodes [ 1 ] ) ) . toBeTruthy ( ) ;
607+ async . done ( ) ;
608+ } ) ;
609+ } ) ) ;
610+
594611 it ( 'should support render global events from multiple directives' , inject ( [ TestBed , AsyncTestCompleter ] , ( tb , async ) => {
595612 tb . overrideView ( MyComp , new View ( {
596613 template : '<div *if="ctxBoolProp" listener listenerother></div>' ,
@@ -1162,6 +1179,30 @@ class DecoratorListeningDomEventOther {
11621179 }
11631180}
11641181
1182+ @Decorator ( {
1183+ selector : '[listenerprevent]' ,
1184+ hostListeners : {
1185+ 'click' : 'onEvent($event)'
1186+ }
1187+ } )
1188+ class DecoratorListeningDomEventPrevent {
1189+ onEvent ( event ) {
1190+ return false ;
1191+ }
1192+ }
1193+
1194+ @Decorator ( {
1195+ selector : '[listenernoprevent]' ,
1196+ hostListeners : {
1197+ 'click' : 'onEvent($event)'
1198+ }
1199+ } )
1200+ class DecoratorListeningDomEventNoPrevent {
1201+ onEvent ( event ) {
1202+ return true ;
1203+ }
1204+ }
1205+
11651206@Component ( {
11661207 selector : '[id]' ,
11671208 properties : { 'id' : 'id' }
0 commit comments