繁体   English   中英

Jest 测试套件无法使用 await 运行

[英]Jest Test suite failed to run with await

我得到了一个带有async方法的 Javascript class (当然里面有await )。

我正在尝试测试此方法,因此我尝试使用此行添加测试:

const res = await myObj.theAsyncMethod("param");

此行导致错误:

测试套件无法运行

它指向await作为错误。 如果我删除await ,测试不会运行失败。

我该如何解决这个问题?

第一次检查,上面的代码是否在异步 function 中? await 调用无法单独解决。

开玩笑的例子:

it("test async", async ()=> { ... });

有关示例,请参阅 async/await 上的 JS 文档。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM