reactjs - 开玩笑拒绝功能失败
问题描述
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 | });
解决方案
我想你想要await expect(fetchDataPromise()).rejects.toEqual("error");
这将断言拒绝的值为“错误”。该toThrow
方法断言一个Error
被抛出,即throw new Error('fart bubble')
。
推荐阅读
- python - Scrapy 获取跨越多行和嵌套元素内的文本
- python - Emacs:自动填充模式 - 如何更改行尾字符?
- html - 谷歌地图有额外的宽度
- apostrophe-cms - Apostrophe CMS:在嵌套连接中获取片段数据(joinByArray – joinByOne)
- javascript - 使用 kepresses 和 if 语句来启用和禁用元素
- assembly - 如何在装配臂中打印多个字符串?
- javascript - 使用 Ionic 4 Angular Fire Auth 保护的无限 console.logging
- azure - 创建函数应用时出现“此区域不允许此订阅的缩放操作”错误
- ios - 如何从 A 中减去 UIBezierPath A&B 的交集?
- c# - 在c#中将基类动态转换为子类