Unable to simulate keypress event in Angular 2 unit test (Jasmine)

后端 未结 3 1521
粉色の甜心
粉色の甜心 2020-12-30 22:20

I am using a directive to get the data from input used as a filter text.

here is my hostlistener in the directive:

@HostListener(\'input\', [\'$event         


        
3条回答
  •  一个人的身影
    2020-12-30 23:11

    If you wish to use a key code (or "which"), you can do this:

    // @HostListener('document:keypress')
    
    const escapeEvent: any = document.createEvent('CustomEvent');
    escapeEvent.which = 27;
    escapeEvent.initEvent('keypress', true, true);
    document.dispatchEvent(escapeEvent);
    

提交回复
热议问题