Я работаю над тестовыми примерами angular и пытаюсь шпионить за методом. component.ts
Изменить1
beforeEach(async () => {
service = new CommonserviceService(http);
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule, RouterTestingModule],
declarations: [ Component ]
})
.compileComponents();
});
beforeEach(() => {
let dummyResponse ={"MESSAGETYPE":"Success","RESPONSE":
"[{\"name\":\"name 1\"}]"};
spyOn(service, 'getADHealth').and.returnValue(of(dummyResponse));
fixture = TestBed.createComponent(Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
getMainStatus(): void {
let health = this.cmnService.getStatus();
health.subscribe(response => {
this.activitySpinnerModal.nativeElement.isOpened = false;
this.status = JSON.parse(response["RESPONSE"]);
},
error => {
this.notificationHeading = "Status Details"
});
}
component.spec.ts
t('should get the status', () => {
let dummyResponse ={"MESSAGETYPE":"Success","RESPONSE":
"[{\"name\":\"name 1\"}]"};
let dummyStatus: Status[]=[{"ename": "name 1"}];
component.getMainStatus();
spyOn(service, 'getStatus').and.returnValue(of(dummyResponse));
const response = service.getStatus();
console.log('response-'+response)
expect(component.status).toEqual(dummyStatus);
});
Я пробовал шпионить за фальшивыми вызовами, оба условия component.status
становятся неопределенными. Полностью застрял в этом вопросе. Любой может мне помочь
Последующие ниже вопросы