const fetchDataPromise = (cal) => Promise.reject("error");
test("the fetch fails with an error2", async () => {
await expect(fetchDataPromise()).rejects.toThrow("error");
});
Expected substring: "error" Received function did not throw 25 | 26 | test("the fetch fails with an error2", async () => { > 27 | await expect(fetchDataPromise()).rejects.toThrow("error"); | ^ 28 | });
答案 0 :(得分:2)
我认为您想要await expect(fetchDataPromise()).rejects.toEqual("error");
这将断言拒绝的值是“错误”。 toThrow
方法断言已抛出Error
,即throw new Error('fart bubble')
。