规范没有期望控制台错误,尽管存在期望 [英] Spec has no expectation console error although expect is present

查看:40
本文介绍了规范没有期望控制台错误,尽管存在期望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须期待的规范,它说没有期望...

I have the spec that has to expect still it says there are no expectations...

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应该单击技术人员的是"按钮,并检查保存并继续"功能没有期望... 你能建议...

It throws the error as spec testComponent should click on yes button of the technician and check save&continue functionality has no expectations... Can you please suggest...

推荐答案

您应该在asyncfakeAsync块中添加回调,否则所有代码将同步运行而不会遇到任何expects.

You should add your callback within an async or fakeAsync block or else all your code would run synchronously without encountering any expects.

这是因为您在异步运行的fixture.whenStable().then(() => {....})中包含断言.

This is because you are having assertions inside fixture.whenStable().then(() => {....}) which runs asynchronously.

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();
    ........

}));

这篇关于规范没有期望控制台错误,尽管存在期望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆