【发布时间】:2020-03-31 18:56:22
【问题描述】:
通过了
test('test_test', async () => {
try {
const received = true;
const expected = false;
expect(received).toBe(expected);
} catch (err) {
return err
}
});
这应该失败
test('test_test', () => {
try {
const received = true;
const expected = false;
expect(received).toBe(expected);
} catch (err) {
return err
}
});
我有一个使用 async 和 await 的函数,这就是测试不会失败的原因,所以我试图了解如何让 top 失败。
【问题讨论】:
-
为什么会有
try和catch?如果你删除它们,测试就会失败,async与否。 -
我将它与 CircleCi 一起使用,它说在使用异步等待的地方使用 try catchs
-
你能链接那个建议吗?我更倾向于遵循 Jest 自己的指导:jestjs.io/docs/en/tutorial-async;如果您尝试测试您正在测试的代码正确抛出错误,您只需要捕获错误。
-
只是按原样运行了一些测试代码,CircleCi 没有抱怨。你是对的,它的尝试。为了清楚起见,这是圈子的消息
(node:727) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
标签: javascript asynchronous async-await jestjs