import { ComponentFixture } from '@angular/core/testing' ; import { DebugElement } from '@angular/core' ; import { By } from '@angular/platform-browser' ; export enum KeyCode { Tab = 9 , Enter = 13 , Esc = 27 , Space = 32 , ArrowUp = 38 , ArrowDown = 40 , Backspace = 8 } export class NgSelectTestHelpers { public static selectOption ( fixture , id , key , index ) { NgSelectTestHelpers . triggerKeyDownEvent ( NgSelectTestHelpers . getNgSelectElement ( fixture , id ) , KeyCode . Space ) ; for ( let i = 0 ; i < index ; i ++ ) { NgSelectTestHelpers . triggerKeyDownEvent ( NgSelectTestHelpers . getNgSelectElement ( fixture , id ) , key ) ; } NgSelectTestHelpers . triggerKeyDownEvent ( NgSelectTestHelpers . getNgSelectElement ( fixture , id ) , KeyCode . Enter ) ; } public static getNgSelectElement ( fixture , id ) { return fixture . debugElement . query ( By . css ( `#${ id }` ) ) ; } public static triggerKeyDownEvent ( element , key ) { element . triggerEventHandler ( 'keydown' , { which : key , preventDefault : ( ) => { } , stopPropagation : ( ) => { } , } ) ; } }