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

195
Views
Prueba de un servicio: cómo inyectar el servicio probado solo una vez
 it('should ...', inject([XService], (service: XService) => { expect(service).toBeTruthy(); }));

De esta manera puedo usar el servicio dentro de 'eso'. Hay mucho más "eso" y no quiero inyectar servicio cada vez. Me gustaría inyectar el servicio una vez en algún lugar al principio (en beforeEach, por ejemplo), pero no puedo. xService tiene muchas dependencias dentro del constructor que también me gustaría obtener.

La única forma en que pude haber hecho esto fue establecer todos esos valores dentro del primer 'eso'.

 let xService: XService; let yService: YService; let zService: ZService; beforeEach(() => ...); it('should ...', inject([XService], (service: XService) => { xService = service; yService = xService['yService']; zService = xService['zService']; expect(xService).toBeTruthy(); }));

Pero personalmente creo que esta es una solución fea. ¿Puedo de alguna manera moverlo a beforeEach?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

En lugar de inject , intente usar TestBed.get() . Es básicamente la misma funcionalidad, y su problema se puede resolver fácilmente:

 let xService: XService; let yService: YService; let zService: ZService; beforeEach( () => { TestBed.configureTestingModule( ... ).compileComponents(); xService = TestBed.get( XService ); yService = TestBed.get( YService ); zService = TestBed.get( ZService ); } ); it( 'should ...',() => { expect( xService instanceof XService ).toBe( true ); } );
over 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!