node.js - 我如何等待 exec 进程在 Jest 中完成?

标签 node.js jestjs

我有以下测试,但我似乎无法让 Jest 等待我的 exec 调用完成运行:

var exec = require('child_process').exec

test('render', async () => {
    await exec('./render.local.sh', (err, out) => {
        console.log(err, out)
        expect(...some file to be created)
    });
})

我应该怎么做才能让 jest 等待 exec 回调被调用?

最佳答案

您需要在断言后调用 done()

test('render', async (done) => {
    await exec('./render.local.sh', (err, out) => {
        console.log(err, out);
        expect(...some file to be created);
        done();
    });
})

这将标记测试完成。

关于node.js - 我如何等待 exec 进程在 Jest 中完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53268672/

相关文章:

node.js - webpack 编译出错

javascript - 类型错误 : dispatch is not a function when I try to test a method using JEST

node.js - Node JS POST 多部分/表单数据请求

node.js - Firebase 功能 : if value exists, 行动然后删除

node.js - NodeJS 和 Express : How to print all the parameters passed in GET and POST request

unit-testing - 开 Jest mock document.referrer

javascript - 如何为 Jest 指定模块目录?

reactjs - 如何实现Axios和Hooks的Jest测试-useEffect

javascript - 开 Jest : Testing for type or null

arrays - 如何在 Node.js 中通过 Mongoose 使用点(.) 进行查询以及如何添加空数组