[英]expecting method call from another method failing on test
Here is the function:这是 function:
handleAddClinic() {
HFSClinicTableSchema.headers.map((th) =>
th.checked ? (th.checked = false) : th
);
this.popTableSchema = { ...HFSClinicTableSchema, rows: [] };
this.openDialog(this.popupTemp);
}
openDialog(templateRef: TemplateRef<HTMLAllCollection>) {
const dialogRef = this.dialog.open(templateRef);
dialogRef.afterClosed().subscribe((result) => {
console.log(`Dialog result: ${result}`, HFSClinicTableSchema);
});
}
here is the spec i do:这是我做的规范:
fit('should reset the page', fakeAsync(() => {
spyOn(component, 'handleAddClinic');
spyOn(component, 'openDialog');
const addButton = fixture.debugElement.query(
By.css('button#btnAddClinic')
);
addButton.nativeElement.click();
tick();
expect(component.handleAddClinic).toHaveBeenCalled(); //ok
tick(5000);
expect(component.openDialog).toHaveBeenCalled(); // error
}));
event though i given 5ms, my testing is failing at;尽管我给了 5 毫秒,但我的测试失败了;
tick(5000); expect(component.openDialog).toHaveBeenCalled();
error:错误:
Error: Expected spy openDialog to have been called.
at <Jasmine>
Really not able to understand the issue.真的无法理解这个问题。 any one help me to understand please?
有人帮我理解吗?
fit('should reset the page', () => {
spyOn(component, 'handleAddClinic').and.callThrough();
spyOn(component, 'openDialog');
const addButton = fixture.debugElement.query(By.css('button#btnAddClinic'));
addButton.nativeElement.click();
expect(component.handleAddClinic).toHaveBeenCalled();
expect(component.openDialog).toHaveBeenCalled();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.