gpt4 book ai didi

angular - 尽管存在期望,但规范没有期望控制台错误

转载 作者:行者123 更新时间:2023-12-04 01:14:13 25 4
gpt4 key购买 nike

我有必须期待的规范,它仍然说没有期望......

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();
});
});
});
它抛出错误,因为规范 testComponent 应该点击技术人员的"is"按钮并检查保存和继续功能没有期望......
能不能给点建议...

最佳答案

您应该在 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();
........

}));

关于angular - 尽管存在期望,但规范没有期望控制台错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54642650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com