【发布时间】:2020-07-12 05:52:09
【问题描述】:
1. Jest Docs:一个异步示例 https://jestjs.io/docs/en/tutorial-async
2。我的测试
describe('some test', () => {
it('sets the correct instance properties ', async () => {
const importService = new ImportService();
const something = await importService.import();
expect(something).toEqual(123);
expect(importService.files).toEqual(files);
});
});
-
错误:
Can not use keyword 'await' outside an async function -
.babelconfig拥有"@babel/preset-env",
我有 async 关键字,但它仍然中断。
【问题讨论】:
-
describe('some test', () => {不是异步的。 -
文档中有一些示例,
it使用await。我假设那些its 在describe -
我没有在描述上使用异步,我正在使用它
-
不支持在“Returning a Promise from "describe" 中添加异步来描述结果。测试必须同步定义。从 "describe" 返回值将在 Jest 的未来版本中失败。 "
-
不,describe 不需要
async。您的示例很好,并且在我的测试中本地工作。它一定是别的东西 -import函数在其实现中使用await吗?如果您可以发布完整的错误,可能会有一些线索...
标签: javascript testing jestjs