toThrow 无法捕捉的错误
function foo() {
throw new Error('error')
}
expect(foo()).toThrow()
如下写法是错误的,这样 jest 捕捉到错误,传入 expect 的参数应该是函数,而不是将函数执行传入:
expect(foo).toThrow()
Feb 14, 2023 · 5min
function foo() {
throw new Error('error')
}
expect(foo()).toThrow()
如下写法是错误的,这样 jest 捕捉到错误,传入 expect 的参数应该是函数,而不是将函数执行传入:
expect(foo).toThrow()