Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
TypeError karma test: suscribirse no es una función

Tengo una prueba de unidad de karma y la prueba falla con el siguiente error.

this.gridApi.getScaleWidth().subscribe no es una función

GridApi.ts

 export class GridApi { private scaleWidthSubject = new BehaviorSubject<{value: number}>({value: 0}); public getScaleWidth(): Observable<{value:number}> { return this.scaleWidthSubject; } }

GridComponent.ts

 export class GridComponent implements OnInit, OnDestroy, AfterViewInit { private subscribeToValueChanges() { this.scaleWidth$ = this.gridApi.getScaleWidth().subscribe( width => { this.scaleWidth = width.value; }); } }

Componente.spec.ts

 describe('GridComponent', () => { beforeEach(async () => { const mockGridApiService = jasmine.createSpyObj("GridApi", { getScaleWidth () : Observable<{value: number}> { let scaleWidthSubject = new BehaviorSubject<{value: number}>({value: 0}); return scaleWidthSubject.asObservable(); } }); } await TestBed.configureTestingModule({ providers: [ { provide: GridApi, useValue: mockGridApiService} ], imports: [ HttpClientModule ], declarations: [ GridComponent ] }) }

¿Qué debe devolver el getScaleWidth() simulado para pasar la prueba? No estoy seguro de lo que me estoy perdiendo aquí.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

describe('GridComponent', () => { const mockGridService = jasmine.createSpyObj<GridApi>('GridApi', ['getScaleWidth']) beforeEach(() => { mockGridService.getScaleWidth.and.returnValue(of({ value: 0 })); }); await TestBed.configureTestingModule({ providers: [ { provide: GridApi, useValue: mockGridService} ], imports: [HttpClientModule], declarations: [ GridComponent ] }) it('should call getScaleWidth from service', () => { // the component function that triggers the service call is private // make the call from component expect(mockGridService.getScaleWidth).toHaveBeenCalled(); mockGridService.getScaleWidth().subscribe(response => { expect(response.value === 0) }) }) }
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda