【发布时间】:2019-04-15 10:54:34
【问题描述】:
我有以下简单的测试设置:
test('what did I do to deserve this', async () => {
expect.assertions(1)
const data = await fetchData() // or fetchData2
expect(data).toBe('peanut butter')
})
async function fetchData () {
return "peanut butter"
}
async function fetchData2 () {
return knex.select('name').from('foos')
}
当我使用fetchData时,玩笑愉快地结束了。
但是当我使用fetchData2 时,它会抱怨:
Jest 在测试运行完成后一秒没有退出。
这通常意味着存在未执行的异步操作 在您的测试中停止。考虑运行 Jest
--detectOpenHandles解决此问题。
data 变量确实有 db 查询的结果,API 中更高级别的其他调用者可以很好地解析查询并继续执行其他语句。
我试过了:
-
--detectOpenHandles标志,但它没有显示任何内容。 - 为
fetchData2制作期望通行证,以防它是the issue described here - 将
donearg 传递给test中的异步函数。它确实存在,但调用它并不能修复警告。 - 向它抛出 try/catch 块
感谢您提供的帮助。
事物的版本:
- 节点 v11.1.0
- “笑话”:“^23.6.0”
- “knex”:“^0.15.2”
【问题讨论】: