Mocha:是否存在测试后 before hook 运行 的情况?
Mocha: Is there a scenario where a before hook would run after a test?
我的 before hook 是 运行 在第一次测试之后,在第二次测试结束时
我的 before hook 的代码:
before(function () {
insightFacade.addDataset("courses", content)
.then(function (result: InsightResponse) {
console.log("then");
})
.catch(function (err: InsightResponse) {
console.log("catch");
});
});
还需要注意的是,有时前 2 个测试而不是前 1 个会失败,这取决于我如何安排我的测试,但第二个测试总是失败
你没有return承诺,所以摩卡不知道等待。 before
挂钩异步将任务排队到 运行,同时开始第一个测试。
before(function () {
<b>return</b> insightFacade.addDataset("courses", content)
.then(function (result: InsightResponse) {
console.log("then");
})
.catch(function (err: InsightResponse) {
console.log("catch");
});
});
我的 before hook 是 运行 在第一次测试之后,在第二次测试结束时
我的 before hook 的代码:
before(function () {
insightFacade.addDataset("courses", content)
.then(function (result: InsightResponse) {
console.log("then");
})
.catch(function (err: InsightResponse) {
console.log("catch");
});
});
还需要注意的是,有时前 2 个测试而不是前 1 个会失败,这取决于我如何安排我的测试,但第二个测试总是失败
你没有return承诺,所以摩卡不知道等待。 before
挂钩异步将任务排队到 运行,同时开始第一个测试。
before(function () {
<b>return</b> insightFacade.addDataset("courses", content)
.then(function (result: InsightResponse) {
console.log("then");
})
.catch(function (err: InsightResponse) {
console.log("catch");
});
});