我正在尝试测试一个没有被抛出的错误,我在我的测试中做了以下操作:
await expect(() => execute(1, 1)).rejects.not.toThrow()
当execute
抛出错误时,测试失败,正如我所希望的那样。然而,当execute
解析成功时,我得到以下测试失败:
Received promise resolved instead of rejected
Resolved to value: undefined
我以前用过Jasmine做这种事情,它很高兴地做expect(() => codeThrowingError).not.toThrow()
,但Jest的语法似乎有点折磨,我不确定如何得到这个权利。
Works great with https://stackoverflow.com/users/3001761/jonrsharpe response about doingawait expect(execute(1, 1)).resolves.toEqual(expect.anything())