我想测试,因为他们正在通过测试,如果他们没有抛出错误
例如
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()
解决这个问题的方法是 chai-as-promise 图书馆
chai-as-promise
const chai = require('chai'); const chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); const expect = chai.expect; expect(sum(1, 2)).to.eventually.not.be.rejectedWith(Error)