查看其他问题,无法真正找到问题的原因。我正在尝试使用摩卡进行测试。确保在此摩卡测试中调用done()回调
it("Should not do the work",function(done) {
axios
.post("x/y",{ id:a2 })
.then(function(res) {
assert(false,"Should not do the work");
done();
})
.catch(function(res) {
assert.equal(HttpStatus.CONFLICT,res.status);
done();
});
});
it("Should do the work",function(done) {
axios
.post("/x/y",{ id: a1 })
.then(function(res) {
done();
})
.catch(done);
});
结果是:
√ Should not do the work (64ms)
1) Should do the work
1 passing (20s)
1 failing
1) Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
增加超时没有工作。
不要忘记你可以简单'返回'在摩卡的承诺,它会相应地处理它。在你的第一个例子中,你确定这些块实际上被执行了吗?我会检查它是否触发。 – tadman