我见过这个问题,它希望 aPromise起作用。在我的情况下Error,在 a 之前和之外抛出Promise。
在这种情况下如何断言错误?我已经尝试了以下选项。
test('Method should throw Error', async () => {
let throwThis = async () => {
throw new Error();
};
await expect(throwThis).toThrow(Error);
await expect(throwThis).rejects.toThrow(Error);
});
Run Code Online (Sandbox Code Playgroud)