[英]how can I assert throw when `new constructor()` with mocha and chai
[英]In Mocha can I assert that a request times out?
我正在测试/确认一些数据库锁的内容,并且我想站起来进行一个测试,该测试将确认如果我锁定该行,请求(“ request-promise”库)将挂起。
一些无效的想法是
request(options).catch((response) => {})
assert.throws(fn, Error, "timeout")
我继续收到此消息: Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
有没有办法断言此超时发生?
在Mocha测试中(或before
describe
,等等), this.timeout(msec)
将更改测试可以运行多长时间,然后Mocha才会认为测试失败。
查看Mocha文档以获取更多信息。
我的解决方案是将超时时间设置为预期超时时间的一半。
setTimeout(function(){ done(); })
然后在我的端点诺言回应中
done(new Error("Timeout should have happened.");
这样,如果发生超时,则会调用done
。 如果没有发生,则done
将被错误调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.