在 Mocha/Chain 启动 block 中测试以下内容,代码永远不会按预期等待。相反,日志报告创建开始,然后记录测试(不包括),然后报告索引创建完成。
Mocha 不应该在 Promise 被解决或拒绝之前退出 before-each block 吗?
我错过了什么?
module.exports.prototype.setup = function (term) {
this.logger.info("Re-creating the index '%s'", $index);
return this.client.indices.delete({
index: $index,
ignore: [404]
}).then((err, resp, respcode) => {
this.logger.info("Creating index '%s'", $index);
return this.client.indices.create({
index: $index,
body: this.schemaBody
});
});
};
最佳答案
您需要写一个async test测试 promise 。
it("should do something", (done) => {
setup("stuff").then((index) => {
/* test index */
done();
});
});
您还可以从测试中返回一个 promise ,mocha 将等待它解决。
it("should do something", () => {
return setup("stuff").then((index) => {
/* test index */
});
});
关于javascript - ElasticSearch JavaScript promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38020261/