我正在写一个async测试,期望async函数抛出像这样:
it("expects to have failed", async () => {
let getBadResults = async () => {
await failingAsyncTest()
}
expect(await getBadResults()).toThrow()
})
但玩笑只是失败而不是通过测试:
FAIL src/failing-test.spec.js
● expects to have failed
Failed: I should fail!
如果我重写这个测试,看起来像这样:
expect(async () => {
await failingAsyncTest()
}).toThrow()
我得到这个错误,而不是通过测试:
expect(function).toThrow(undefined)
Expected the function to throw an error.
But it didn't throw anything.