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

365
Views
¿Cómo probar componentes con TranslatePipe de ngx-translate? TypeError: no se pueden leer las propiedades de undefined (leyendo 'suscribirse')

Tengo un componente que en sí mismo no inyecta TranslationService en el constructor. Pero uso la tubería de translate en los archivos html. La prueba siempre falla con este error:

 TypeError: Cannot read properties of undefined (reading 'subscribe') at TranslatePipe.transform (http://localhost:9876/_karma_webpack_/vendor.js:107322:75) at ɵɵpipeBind1 (http://localhost:9876/_karma_webpack_/vendor.js:80764:22) at MyComponent_Template (ng:///MyComponent.js:406:33) at executeTemplate (http://localhost:9876/_karma_webpack_/vendor.js:64582:9) at refreshView (http://localhost:9876/_karma_webpack_/vendor.js:64448:13) at refreshComponent (http://localhost:9876/_karma_webpack_/vendor.js:65619:13) at refreshChildComponents (http://localhost:9876/_karma_webpack_/vendor.js:64245:9) at refreshView (http://localhost:9876/_karma_webpack_/vendor.js:64498:13) at renderComponentOrTemplate (http://localhost:9876/_karma_webpack_/vendor.js:64562:9) at tickRootContext (http://localhost:9876/_karma_webpack_/vendor.js:65793:9)

Mi prueba se ve así:

 describe('MyComponent', () => { let component: MyComponent; let fixture: ComponentFixture<MyComponent>; let httpClient: HttpClient; let httpTestingController: HttpTestingController; beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ MyComponent, TranslatePipe, ], imports: [ HttpClientTestingModule, RouterTestingModule, ], providers: [ { provide: TranslateService, useClass: TranslationServiceStub, } ], schemas: [NO_ERRORS_SCHEMA] }) .compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(MyComponent); component = fixture.componentInstance; httpClient = TestBed.inject(HttpClient); httpTestingController = TestBed.inject(HttpTestingController); fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); });

Antes de agregar TranslationServiceStub, falló debido a que faltaba TranslationService. Ahora no estoy seguro de cómo arreglar esto. ¿Algunas ideas?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Bien, como siempre, encontré la respuesta después de quejarme aquí.

Eliminé TranslationServiceStub y TranslatePipe y agregué

 TranslateModule.forRoot({ loader: { provide: TranslateLoader, useClass: TranslateFakeLoader, } })

a las importaciones. Ahora funciona.

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!