我有必须期待的规范,但它仍然说没有期望......
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();
});
});
});
它会抛出错误,因为规范测试组件应该单击技术人员的“是”按钮并检查“保存并继续”功能没有预期...
可以请您推荐一下吗...
您应该在async
or 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();
........
}));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)