我有以下的测试案例:与摩卡做()和异步等待悖论问题
it("should pass the test", async function (done) {
await asyncFunction();
true.should.eq(true);
done();
});
运行它断言:
Error: Resolution method is overspecified. Specify a callback or return a Promise; not both.
如果我删除done();
声明,它断言:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
如何解决这个悖论?
当你删除'done();',你是否也删除了'd函数中的一个参数? –
不应该有返回声明吗?我在印象之下所有的同步功能需要返回解决。 –
@ShyamBabu:不,如果没有明确的'return',他们等待的最后一个承诺完成后,他们用'undefined'解决。 –