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

Spec has no expectation console error although expect is present

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

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 应该点击技术人员的是按钮并检查保存和继续功能没有预期...... 你能推荐一下吗...

您应该在 asyncfakeAsync 块中添加您的回调,否则您的所有代码将 运行 同步而不会遇到任何 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();
    ........

}));