相关疑难解决方法(0)

测试摩卡的预期失败

使用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)

这可能吗?

unit-testing mocha.js node.js

18
推荐指数
6
解决办法
3万
查看次数

标签 统计

mocha.js ×1

node.js ×1

unit-testing ×1