lundi 16 mars 2020

Angular TestBed.inject type error when injecting into a spy

I want to inject a service into a serviceSpy in the same way as the angular example shows. Angular 9 https://angular.io/guide/testing#service-tests

let masterService: MasterService;
let valueServiceSpy: jasmine.SpyObj<ValueService>;

beforeEach(() => {
const spy = jasmine.createSpyObj('ValueService', ['getValue']);

TestBed.configureTestingModule({
// Provide both the service-to-test and its (spy) dependency
providers: [
  MasterService,
  { provide: ValueService, useValue: spy }
]
});
// Inject both the service-to-test and its (spy) dependency
masterService = TestBed.inject(MasterService);
valueServiceSpy = TestBed.inject(ValueService);
});

intellij shows me this error TS2322: Type 'ValueService' is not assignable to type SpyObj<ValueService>

can someone help?

Aucun commentaire:

Enregistrer un commentaire