Это мой .spec
файл.для обслуживания контента.Я сгенерировал этот файл с помощью плагина "SimonTest".Мой первый тест пройден, но второй тест, где ngOnInit makes expected calls
не проходит.Вот мой код.
// servicing.component.spec.ts
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ServicingService } from './servicing.service';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { StorageService } from 'angular-nexus-uiux/services';
import { BrandingService } from '/branding.service';
import { ServicingComponent } from './servicing.component';
fdescribe('ServicingComponent', () => {
let comp: ServicingComponent;
let fixture: ComponentFixture<ServicingComponent>;
beforeEach(() => {
const servicingServiceStub = {
tagSiteCatalyst: () => ({ }),
getServicingContent: () => ({
subscribe: () => ({
})
})
};
const routerStub = {
events: {
filter: () => ({
subscribe: () => ({})
})
},
url: {
split: () => ({})
}
};
const activatedRouteStub = {
data: {
subscribe: () => ({})
}
};
const storageServiceStub = {
get: () => ({})
};
const brandingServiceStub = {};
TestBed.configureTestingModule({
declarations: [ ServicingComponent ],
schemas: [ NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA ],
providers: [
{ provide: ServicingService, useValue: servicingServiceStub },
{ provide: Router, useValue: routerStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: StorageService, useValue: storageServiceStub },
{ provide: BrandingService, useValue: brandingServiceStub }
]
});
fixture = TestBed.createComponent(ServicingComponent);
comp = fixture.componentInstance;
});
it('can load instance', () => {
expect(comp).toBeTruthy();
});
describe('ngOnInit', () => {
it('makes expected calls', () => {
const servicingServiceStub: ServicingService = fixture.debugElement.injector.get(ServicingService);
const storageServiceStub: StorageService = fixture.debugElement.injector.get(StorageService);
spyOn(servicingServiceStub, 'tagSiteCatalyst');
spyOn(servicingServiceStub, 'getServicingContent');
spyOn(storageServiceStub, 'get');
comp.ngOnInit();
expect(servicingServiceStub.tagSiteCatalyst).toHaveBeenCalled();
expect(servicingServiceStub.getServicingContent).toHaveBeenCalled();
expect(storageServiceStub.get).toHaveBeenCalled();
});
});
});
Я получаю сообщение об ошибке в карме как Expected spy getServicingContent to have been called.
Я не уверен, почему я получаю это.Может ли кто-нибудь помочь мне в этом.