export function dispatchEvent ( node , event ) { node . dispatchEvent ( event ) ; return event ; } export function dispatchKeyboardEvent ( node , type , keyCode ) { return dispatchEvent ( node , createKeyboardEvent ( type , keyCode ) ) as KeyboardEvent ; } export function createKeyboardEvent ( type , keyCode , target ? , key ? ) { const event = document . createEvent ( 'KeyboardEvent' ) as any ; const initEventFn = ( event . initKeyEvent || event . initKeyboardEvent ) . bind ( event ) ; const originalPreventDefault = event . preventDefault ; initEventFn ( type , true , true , window , 0 , 0 , 0 , 0 , 0 , keyCode ) ; Object . defineProperties ( event , { keyCode : { get : ( ) => keyCode } , key : { get : ( ) => key } , target : { get : ( ) => target } } ) ; event . preventDefault = function ( ) { Object . defineProperty ( event , 'defaultPrevented' , { get : ( ) => true } ) ; return originalPreventDefault . apply ( this , arguments ) ; } ; return event ; }