我有一个必须期待的规范,它说没有期望...
it('should click on yes button of technician and check save&continue
functionality', () => {
const saveAndContinue =
fixture.debugElement.query(By.css(saveContinueBtn)).nativeElement;
saveAndContinue.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
const spy = spyOn(component,
'isSaveAndContinueClicked').and.callThrough();
expect(component).toBeDefined();
expect(spy);
component.isSaveAndContinueClicked();
expect(component.isSaveAndContinueClicked).toHaveBeenCalled();
const yesbutton =
fixture.debugElement.query(By.css('#yesButton')).nativeElement;
expect(yesbutton).toBeTruthy();
fixture.detectChanges();
fixture.whenStable().then(() => {
spyOn(component, 'change').and.callThrough();
spyOn(component, 'change2').and.callThrough();
yesbutton.click();
expect(component.change).toHaveBeenCalled();
expect(component.change2).toHaveBeenCalled();
});
});
});
它抛出错误,因为spec testComponent应该单击技术人员的“是”按钮,并检查“保存并继续”功能没有期望... 你能建议...
答案 0 :(得分:0)
您应该在async
或fakeAsync
块中添加回调,否则所有代码将同步运行而不会遇到任何expects
。
这是因为您在fixture.whenStable().then(() => {....})
内部有断言,该断言是异步运行的。
it('should click on yes button of technician and check save&continue
functionality', async(() => {
const saveAndContinue =
fixture.debugElement.query(By.css(saveContinueBtn)).nativeElement;
saveAndContinue.click();
........
}));