用`async`进行角度测试会导致Jasmine超时吗? [英] Angular test with `async` causing Jasmine timeout?
本文介绍了用`async`进行角度测试会导致Jasmine超时吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近将一个项目升级到Angular 6,现在以前运行良好的测试现在失败了.这是其中一个测试的示例:
I recently upgraded a project to Angular 6, and now tests that were working fine before are now failing. Here's an example of one of those tests:
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [CampaignsDetailScheduleComponent],
imports: [
SomeModule,
ReactiveFormsModule,
TranslateModule.forRoot({
loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
}),
StoreModule.forRoot({})
],
providers: [{ provide: ConfigService, useValue: ConfigServiceMock }],
schemas: [NO_ERRORS_SCHEMA]
});
fixture = TestBed.createComponent(CampaignsDetailScheduleComponent);
comp = fixture.componentInstance; // Component test instance
_store = fixture.debugElement.injector.get<Store<State>>(Store);
comp.campaignModel$ = of(CampaignMockData);
fixture.detectChanges();
})
);
it(
'close edit schedule modal',
async(() => {
spyOn(_store, 'dispatch');
comp.onClose();
const args = new ShowHideEditScheduleModal(false);
expect(_store.dispatch).toHaveBeenCalledWith(args);
})
);
Angular 6之前,此测试顺利通过.但是现在在Angular 6下,我得到了错误:
Pre-Angular 6, this test passed with no issues. But now under Angular 6, I get the error:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.--Pendng async tasks are: [type: macroTask, source: setInterval, args: {handleId:4072,isPeriodic:true,delay:0,args:[object Arguments],__creationTrace__:[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]},type: macroTask, source: setInterval, args: {handleId:4075,isPeriodic:true,delay:0,args:[object Arguments],__creationTrace__:[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]}]
有人知道会发生什么吗?
Does anyone have any idea what might be going on?
推荐答案
在每个块之前使用fakeAsync
代替async
.
use fakeAsync
instead of async
in before each block.
这篇关于用`async`进行角度测试会导致Jasmine超时吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文