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

156
Views
Inyección de dependencia en el componente principal y secundario en Angular

Estaba teniendo problemas con una prueba en angular. Lo extraño fue que las pruebas tuvieron éxito con

 ng test

y fracasó con

 ng test --watch=false --browsers=ChromeHeadless --code-coverage

Pero agregar un constructor en el componente secundario resolvió el problema.

Componente principal:

 Component({ templateUrl: './edit-organization.component.html', styleUrls: ['./edit-organization.component.scss'] }) export class EditOrganizationComponent implements OnInit { organization: Organization; errorReason: ErrorReason; organization$: Observable<Organization>; errorCodes: ErrorCode[]; constructor( protected currentUserRoute: ActivatedRoute, protected organizationService: OrganizationService, protected navigationService: NavigationService ) { } ngOnInit(): void { this.organization = this.currentUserRoute.snapshot.data.organization; } updateOrganization(form: NgForm) { ...}

Componente secundario 1 (La prueba solía fallar aquí)

 @Component({ templateUrl: './edit-business-organization-profile.component.html', }) export class EditBusinessOrganizationProfileComponent extends EditOrganizationComponent implements OnInit { organizationServiceTypes: OrganizationServiceType[] = organizationServiceTypes; constructor(readonly currentUserRoute: ActivatedRoute, readonly organizationService: OrganizationService, readonly navigationService: NavigationService) { super(currentUserRoute, organizationService, navigationService); } ngOnInit(): void { super.ngOnInit(); } }

Componente hijo 2 (Las pruebas pasan aquí)

 @Component({ templateUrl: './business-organization-profile.component.html', }) export class BusinessOrganizationProfileComponent extends EditOrganizationComponent implements OnInit { ngOnInit(): void { super.ngOnInit(); } }

Tengo una prueba casi similar para los dos componentes que estaban pasando antes, pero cuando agregué un campo organizationServiceTypes en EditBusinessOrganizationProfileComponent , las pruebas comenzaron a fallar.

Anteriormente no tenía ningún constructor en el componente EditBusinessOrganizationProfileComponent , una vez que agregué el constructor, las pruebas comenzaron a pasar.

¿Alguien puede explicar cómo funciona la inyección de dependencia en este caso, ya que el código funciona perfectamente sin la prueba, es solo la prueba la que se rompe?

about 4 years ago · Juan Pablo Isaza
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!