使用 hapijs/lab 进行测试——done 不是一个函数

Testing using hapijs/lab -- done is not a function

正在尝试为我的 hapi 服务器编写一些测试。以下代码来自 https://github.com/hapijs/lab/issues/79 ,但它失败了,因为 done 不是函数...

const Code = require('code');
const Lab = require('lab');
const lab = exports.lab = Lab.script();
lab.test('expect an error from a promise', (done) => {
    return new Promise((resolve, reject) => {

        try {
            resolve(2);
        }
        catch (err) {
            reject(err);
        }
    }).then((result) => {

        console.log('5) resolved');
        done(new Error('promise should be rejected and caught'));
    }).catch((error) => {

        console.log('5) rejected, this does not trigger');
        Code.expect(error).to.exist();
        done(error);
    });
});

我还应该导入什么才能调用完成?

Failed tests:

  1) expect an error from a promise:

      done is not a function

lab.test 不再 return done 回调,因为它与 hapi v17 兼容。 实验室现在使用 async/await 功能,您可以 return 承诺。 示例见此处:lab docs

"lab": "^14.3.4"好像还是支持donees6 同时。当然,我不能确定是否支持全套 es6 功能,但它满足了我的需求。