Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
Spectator not changing/using different mocks

I have a testing component and few tests that require different mocks to be used by spectator. The problem is I couldn't get specatator to change them dynamicly as the test go on.

Basicly I have 2 mocks that are imported from .json files, one being the right one and the other one is the one with error.

Correct: profitability-customer.json Invalid: profitability-customer-JSON-error-1.json

On test 8 I need spectator to switch mock to invalid one.

Here is what I have:

import * as reportMock from '@app/__mocks__/reports/profitability-customer.json';
import * as reportMockError from '@app/__mocks__/reports/profitability-customer-JSON-error-1.json';

let spectator: Spectator<ProfitabilityCustomerReportComponent>;
beforeEach(() => {
  spectator = createComponent(); 
  spectator.component.reportForm.controls.brands.setValue([testCustomer.brands[1].bkId]);
  testIter++;
});
createComponent = createComponentFactory({
    component: ProfitabilityCustomerReportComponent,
    imports: [SharedModule, HttpClientTestingModule, RouterTestingModule],
    providers: [MapService, DateSelectService,
      mockProvider(HeaderCustomerService, HeaderCustomerServiceMock),
      mockProvider(MapService, MapServiceMock),
      mockProvider(ReportingApiService, myFOO())
    ],
    shallow: false
  });
function myFOO() {
    let ReportingApiServiceMock: any;
    console.log(testIter);
    if (testIter === 8) {
      ReportingApiServiceMock = {
        getReport() {
          return of(reportMockError['profitability-customer-JSON-error-1']);
        }
      };
    } else {
      ReportingApiServiceMock = {
        getReport() {
          return of(reportMock['profitability-customer']);
        }
      };
    }

    return ReportingApiServiceMock;
  };
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda