I just updated my angular app into version 9. Everything works fine excluding the unit tests. After updating, the unit tests not working.
Below is my sample test suite
describe("test Component", () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
],
providers: [
{ provide: InitService, useValue: mockInit },
{ provide: ControlsService, useValue: genericMock },
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
}));
it('should initialize slides', () => {
const fixture = TestBed.createComponent(AppComponent);
const slides = TestBed.inject(SlideChangeService);
const controls = TestBed.inject(ControlsService);
spyOn(slides, 'initialize');
spyOn(controls, 'initialize');
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(slides.initialize).toHaveBeenCalled();
expect(controls.initialize).toHaveBeenCalled();
});
});
});
it works fine before the angular updation, but now it shows below error!!!
Error: <spyOn> : initialize has already been spied upon
so, how we can spy on two different services that using same method name in angular9 unit tests?