Mocha 测试忽略错误

问题描述 投票:0回答:1

我正在尝试编写一个测试,其中函数预计会抛出错误。

it("function throws an expected error", function(done){
                return someAsyncError().then(function(){
                    expect(1).to.be.equal(1)
                })                      
            })

这个测试总是会因为错误而失败。我如何捕获错误以便测试正确? 我不想用

expect(someAsyncError).to.throw()

node.js testing mocha.js chai
1个回答
0
投票

使用 NodeJS assert.throws(),所以你的代码可以是这样的:

 it("function throws an expected error", done => {
   assert.throws(someAsyncError, Error, "Error thrown")
 })
© www.soinside.com 2019 - 2024. All rights reserved.