Steve Fitzsimons
Steve Fitzsimons

Reputation: 3904

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

Upvotes: 5

Views: 14868

Answers (2)

JWP
JWP

Reputation: 6963

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"});

Upvotes: 2

Steve Fitzsimons
Steve Fitzsimons

Reputation: 3904

Thanks to @jonrsharpe

By.css('#someId')

Upvotes: 7

Related Questions