繁体   English   中英

如果函数被声明为异步,为什么 Jest 会通过测试?

[英]Why does Jest pass test if function is declared asynchronous?

这通过

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 的函数,这就是测试不会失败的原因,所以我试图了解如何使顶部失败。

正如@jonrsharpe 建议删除try / catch它现在按预期运行并且失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM