为什么 Mocha 测试在返回 false 时不会失败

Why Isn't a Mocha Test Failing When Returning false

如果你直接做 return false;,mocha 测试不应该失败吗?我的还在通过。为什么?

 describe('some description', function(){
                it('should do something', function (){
                    return false;
                });
            });

来自mocha documentation

Mocha allows you to use any assertion library you want, if it throws an error, it will work! This means you can utilize libraries such as should.js, node's regular assert module, or others.

所以如果你想让你的测试失败抛出一个错误

describe('some description', function() {
  it('should do something', function() {
    throw new Error();
  });
});

您还可以使用以下方法:

describe('some description', function() {
  it('should do something', function() {
    done("Your error message");
  });
});