Javascript Jest异步/等待中断

Javascript Jest异步/等待中断,javascript,testing,jestjs,Javascript,Testing,Jestjs,1。Jest文档:异步示例 2。我的测试 description('sometest',()=>{ 它('设置正确的实例属性',异步()=>{ const importService=new importService(); const something=wait importService.import(); 期望(某事)。托夸尔(123); expect(importService.files).toEqual(files); }); }); 错误: 不能在异步函数外部使用关键字“wa

1。Jest文档:异步示例

2。我的测试

description('sometest',()=>{
它('设置正确的实例属性',异步()=>{
const importService=new importService();
const something=wait importService.import();
期望(某事)。托夸尔(123);
expect(importService.files).toEqual(files);
});
});
  • 错误:
    不能在异步函数外部使用关键字“wait”

  • .babelconfig
    具有
    “@babel/preset env”,


  • 我有async关键字,但它仍然会断开。

    您可能会收到此错误,因为您正在测试的函数之一在使用
    wait
    时缺少
    async


    尝试查看
    ImportService
    的构造函数和方法
    import()

    您可能会收到此错误,因为您正在测试的一个函数在使用
    wait
    的地方缺少
    async


    尝试查看
    ImportService
    的构造函数和方法
    import()

    description('sometest',()=>{
    不是异步的。在文档上有一些例子,使用
    it
    使用
    wait
    。我假设那些
    it
    s在
    descripe
    中,我没有在descripe上使用async,我在it上使用它添加async来描述“从”descripe返回承诺的结果不支持。测试必须同步定义。在Jest的未来版本中,从“描述”返回值将使测试失败。“不需要,descripe不需要
    async
    。您的示例很好,在我的测试中可以在本地运行。它一定是其他原因-
    import
    函数在其实现中是否使用了
    wait
    ?如果您可以发布完整的错误,可能会有一些线索…
    descripe('some test',()=>{
    不是异步的。在文档上有一些例子,使用
    it
    使用
    wait
    。我假设那些
    it
    s在
    descripe
    中,我没有在descripe上使用async,我在it上使用它添加async来描述“从”descripe返回承诺的结果不支持。测试必须同步定义。在Jest的未来版本中,从“描述”返回值将使测试失败。“不,描述不需要
    async
    。您的示例很好,在我的测试中可以在本地运行。它一定是其他原因-
    import
    函数在其实现中是否使用了
    wait
    ?如果您可以发布完整错误,可能会有一些线索。。。