Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 虽然存在expect,但规范没有expect控制台错误_Angular_Unit Testing_Jasmine_Karma Runner - Fatal编程技术网

Angular 虽然存在expect,但规范没有expect控制台错误

Angular 虽然存在expect,但规范没有expect控制台错误,angular,unit-testing,jasmine,karma-runner,Angular,Unit Testing,Jasmine,Karma Runner,我有需要期待的规范,但它说没有期望 it('should click on yes button of technician and check save&continue functionality', () => { const saveAndContinue = fixture.debugElement.query(By.css(saveContinueBtn)).nativeElement; saveAndContinue.click(); fixt

我有需要期待的规范,但它说没有期望

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应单击技术人员的“是”按钮,并检查“保存并继续”功能是否没有预期。。。
您可以建议…

您应该在
异步
fakeAsync
块中添加回调,否则您的所有代码都将同步运行,而不会遇到任何
期望的

这是因为您在fixture.whenStable()中有断言。然后(()=>{….})异步运行

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

}));

关于这个问题,我没有使用async或waitForAsync构造。只有假货救了我的命。