Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Count the number of child components by tag name in angular2 unit testing

I have a parent component which will dynamically insert the child components based on the length of array. I want to test the number of components created, by using its tag name.

<div *ngFor = "let item of phoneList; let i = index">
    <phone-item [item]="item"> </phone-item>
</div>

I want to verify the number of <phone-item></phone-item> created within the html template in angular2 unit testing.

I have very little knowledge on debugElement and nativeElement. This is what I have tried to do.

let el = fixture.debugElement.query(By.css('phone-item'));

But I want the count of child components created.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use DebugElement#queryAll which returns an array. query only returns the first matching

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!