使用Mocha,我试图测试构造函数是否抛出错误.我无法使用expect语法执行此操作,因此我想执行以下操作:
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.
}
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?