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

96
Views
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
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!