jestjs - 异步测试因超时而失败
问题描述
我们在 Angular 12 中的项目中使用 jest 27 来运行我们的单元测试。在本地,这些测试运行正常,但在它们中断的云代理管道中运行它们,出现以下错误:
抛出:“挂钩超时超过 5000 毫秒。如果这是一个长时间运行的测试,请使用 jest.setTimeout(newTimeout) 增加超时值。”
这是代码中断的部分:
const createHost = createHostFactory({
component: Component,
imports: [
TranslateModule.forRoot(),
GridModule,
MaterialWrapperTestingModule,
ReactiveFormsModule,
TooltipModule,
TableEditionToolbarModule,
],
providers: [
{ provide: ContactsService, useValue: contactsServiceSpy },
{ provide: CustomerService, useValue: customerServiceSpy },
{ provide: CustomerDetailFacade, useValue: customerFacadeSpy },
{ provide: HeaderMenuFacade, useValue: headerMenuFacadeSpy },
{ provide: ContextFacade, useValue: contextFacadeSpy },
{ provide: MatDialog, useValue: dialogMock },
],});
beforeEach(() => {
host = createHost('<component-selector></component-selector>', { detectChanges: true,
props: { structure } });
return host.fixture.whenStable();
});
运行测试需要太多时间并且任务失败。
为了解决这个问题,我们做了一些更改,但没有任何帮助:
- 我们已经使用 jest.setTimeout(newTimeout)
- 我们还使用 --runInBand 连续运行测试
解决方案
推荐阅读
- sql-server - 将字符串附加到存储过程中的列值 - SQL Server
- apache-spark - 在 pyspark 中使用 findspark 添加包
- java - 通过 @Rule 在 JUnit 中初始化列表
- asp.net-mvc - API 调用未命中 WebAPI 子文件夹
- c# - ora-00955: 在选择视图期间名称已被现有对象使用
- r - 将具有一组间隔的数据帧转换为一组离散值
- java - 如何将一个字符串设置为另一个字符串的特定字符
- javascript - Vue路由器在第一次加载时不加载组件
- exe - 在 Windows 10 上签名的可执行代码在 Windows 7 中无法识别
- c - 将 32 位正整数转换为空终止字符串的查找表需要多少 RAM