简体   繁体   中英

Why does Jest pass test if function is declared asynchronous?

This passes

test('test_test', async () => {
  try {
    const received = true;
    const expected = false;
    expect(received).toBe(expected);
  } catch (err) {
    return err
  }
});

This fails as it should

test('test_test', () => {
  try {
    const received = true;
    const expected = false;
    expect(received).toBe(expected);
  } catch (err) {
    return err
  }
});

I have a function using async and await and this is the reason the test will not fail so I'm trying to understand how to make the top fail as it should.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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