停止运行摩卡测试

rya*_*zec 4 unit-testing mocha.js node.js

所以我有一些代码在before()任何测试之前执行.在函数中是否有某种方法可以阻止mocha运行任何测试?

before(function() {
  if(someCondition === true) {
    //kill mocha before it executes any tests
  }
});
Run Code Online (Sandbox Code Playgroud)

这样的事情可能吗?

Ger*_*osi 5

您可以done使用错误调用回调:

before(function(done) {
  if(someCondition === true) {
    return done('Error');
  }
});
Run Code Online (Sandbox Code Playgroud)