Angular Jasmine/Karma-第一个测试用例总是失败

Angular Jasmine/Karma-第一个测试用例总是失败,angular,karma-jasmine,Angular,Karma Jasmine,我在.spec.ts文件中有多个测试用例。第一个测试用例总是失败,并显示错误消息 错误:超时-在jasmine.DEFAULT\u Timeout\u INTERVAL指定的超时内未调用异步回调 谁能帮帮我吗 代码段: beforeEach(async(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 2147483647; TestBed.configureTestingModule({ imports

我在.spec.ts文件中有多个测试用例。第一个测试用例总是失败,并显示错误消息 错误:超时-在jasmine.DEFAULT\u Timeout\u INTERVAL指定的超时内未调用异步回调

谁能帮帮我吗

代码段:

beforeEach(async(() => {  

      jasmine.DEFAULT_TIMEOUT_INTERVAL = 2147483647;
      TestBed.configureTestingModule({
          imports: [AppModule, JobModule],
          providers: [ {provide: APP_BASE_HREF, useValue: '/'} ]
      }).compileComponents();

      fixture = TestBed.createComponent(JobListComponent);
      component = fixture.componentInstance;
      debugElement = fixture.debugElement;

      translateService = TestBed.get(TranslateService);
      jobService = TestBed.get(JobService);
      route = TestBed.get(ActivatedRoute);
      _locale = TestBed.get(LOCALE_ID);     


  }));

it('should create the job list component', async(() => { //always this gets failed 
    expect(component).toBeTruthy();             
}));

it('should create the job list component 1', async(() => {              
    expect(component).toBeTruthy();             
}));

下面的代码适用于我。感谢rrd为您提供的巨大帮助

it('should create the data list component', () => {                  
        expect(component).toBeTruthy();             
    });

    it('should initialize data on ngOnInit()', (done) => {                               
        component.ngOnInit();              
        fixture.detectChanges();    

        fixture.whenStable().then(()=>{                                                              
            expect(component.customerList.length).toBeGreaterThanOrEqual(0);   
            done(); 
        });  

    });

删除beforeach()rrd中的async()调用。当我单独运行speculat spec.ts文件时,它就起作用了。但是当我尝试运行项目中的所有spec.ts文件时,我得到了错误****未捕获类型错误:无法读取未定义**********未处理承诺拒绝的属性“afe”:在没有当前规范时使用了“expect”,这可能是因为异步测试超时;区域:ProxyZone;任务:承诺;值:错误:在没有当前规范时使用了“expect”,这可能是因为异步测试超时了******您可能也可以删除it()块上的async()。谢谢…对于没有subscribe调用的it()块,它工作正常。在我的代码中,我有另一个it()块,它有subscribe调用,必须等待结果。我使用代码*********it('should initialized data on ngOnInit()',(done)=>{component.ngOnInit();fixture.detectChanges();fixture.whenStable()。然后(()=>{expect(component.jobDatabase.data.length)。toBeGreaterThanOrEqual(0);完成();});})**************