Mocha和Chai测试期望不会抛出错误

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

我正在与Mocha和Chai做一些测试

我有一些没有返回值的函数,但是如果有错误,它们会抛出错误

如果他们没有引发错误,我想通过进行测试

例如

async function sum(a, b){
    Promise.resolve()
    .then()
    if(typeof(a) !== 'number')
        throw new Error('a should be a number')

    if(typeof(b) !== 'number')  
        throw new Error('b should be a number')

    console.log('the sum is ', a + b)

    return
}

然后,我想测试它是否正在与类似的东西一起工作

expect(sum(1, 2)).not.to.throw()
mocha chai
1个回答
0
投票

解决此问题的方法是使用chai-as-promise

© www.soinside.com 2019 - 2024. All rights reserved.