Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 5 component test get debugElement by ID

I have a component containing 3 select dropdowns with no css classes attached and a unique Id on each. In my component I want to get the elements as DebugElements so that I can test their states after various events have been triggered. From the Angular website there is debugElement.query(By.css('[attribute]'));. How can I get my dropdowns By.id

like image 987
Steve Fitzsimons Avatar asked Mar 07 '23 11:03

Steve Fitzsimons


2 Answers

Thanks to @jonrsharpe

By.css('#someId')
like image 155
Steve Fitzsimons Avatar answered Mar 10 '23 01:03

Steve Fitzsimons


Angular 7 get debugElement by ID

The debugElement.query iterates all debugElements and returns those found to be true via a predicate. This example shows how to do it in one line of code.

var test = fixture.debugElement.query((de)=>{return de.nativeElement.id==="someId"});
like image 29
JWP Avatar answered Mar 10 '23 02:03

JWP