javascript - How to create KeyboardEvent with specific keyCode -
i'm trying simulate keydown event in unit test (angular2/typescript). not have debugelement available, i'm trying emit event on native element. problem have how define keycode when creating keyboardevent. keycode not defined part of keyboardeventinit definition, , on keyboardevent exposed readonly property.
simply adding keycode property (and set obj type ) doesn't work either.
let elm = <htmlelement>content.nativeelement; let ev = new keyboardevent('keydown', { code: '123', //keycode: 345, key: 'a', }); elm.dispatchevent(ev);
any suggestions ?
edit: according mdn link, keycode deprecated , should not used, instead 'code' should used. https://developer.mozilla.org/en-us/docs/web/api/keyboardevent/keycode
Comments
Post a Comment