ale*_*cxe 3 javascript timeout mocha.js
在mocha1.21.0中,引入了一个新设置enableTimeouts(true / false);以及相应的--no-timeouts命令行参数。
问题是,它没有记录在案。
它涵盖哪些用例?什么时候可以禁用超时?
Mocha长期以来一直支持关闭超时功能。使用timeout(0)还会禁用超时。是什么enableTimeouts()让这timeout()没有是把超时和关闭没有忘记什么超时曾经是它关闭之前。例如:
describe("foo", function () {
this.timeout(500);
describe("no timeout", function () {
this.enableTimeouts(false);
it("without a timeout", function (done) {
setTimeout(done, 1000);
});
describe("timeout", function () {
this.enableTimeouts(true);
// From this point on, we are back to a timeout of 500ms.
it("with a timeout", function (done) {
setTimeout(done, 1000);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
我在设计测试时禁用了超时功能,因为我可能不会马上知道会有多大的限制。因此,在进行测试时,将禁用超时,然后以合理的值重新启用它。
我没有遇到必须永久禁用超时才能使测试套件正常工作的情况。