I have the following below code in my Html file :
Product.html
I want to write Unit test case in Angular for input element inside mat-select element in .ts file like below:
it('open the product dropDown', async(() => { componentFixture.detectChanges(); spyOn(searchComponent, 'filterProducts'); let input = componentFixture.debugElement.query(By.css('#txtFilterProduct')); input.triggerEventHandler('keyup', null); componentFixture.detectChanges(); expect(searchComponent.filterProducts).toHaveBeenCalled(); expect(searchComponent.filterProducts).toHaveBeenCalledTimes(1); }));
I am getting the error: calling triggerEventHandler on undefined. Similarly it is giving the same error for mat-option.
Please suggest or tell how we can do unit test for input and mat-option inside mat-select for dropdown
Muthu KumarPosted Mar 6, 2019, 3:31 AM
This may help to you. Please check below link,
https://angular.io/guide/testing#triggereventhandler
https://github.com/angular/angular/issues/11804