我想知道为什么在使用try-catch块后,下面的测试用例仍通过了,虽然它应该失败:
test("test", () => {
try {
expect(true).toBe(false);
} catch (err) {
console.log(err);
}
});
虽然没有try-catch却失败了:
test("test", () => {
expect(true).toBe(false);
});
断言expect(true).toBe(false);
将引发错误,但是使用try-catch块将错误吞并,因此测试通过。