测试摩卡咖啡中的预期故障 [英] Test for expected failure in Mocha
本文介绍了测试摩卡咖啡中的预期故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Mocha,我正在尝试测试构造函数是否引发错误.我无法使用Expect语法执行此操作,因此我想执行以下操作:
Using Mocha, I am attempting to test whether a constructor throws an error. I haven't been able to do this using the expect syntax, so I'd like to do the following:
it('should throw exception when instantiated', function() {
try {
new ErrorThrowingObject();
// Force the test to fail since error wasn't thrown
}
catch (error) {
// Constructor threw Error, so test succeeded.
}
}
这可能吗?
推荐答案
您可以尝试使用 Chai的 throw
构造.例如:
You can try using Chai's throw
construct. For example:
expect(Constructor).to.throw(Error);
这篇关于测试摩卡咖啡中的预期故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文