Open
Description
Bug
package
version: 4.0.1node
version: 18.18.0yarn
version: 1.22.19
Relevant code or config
// my.test.js
function invokeWithTry(callback) {
try {
return callback();
} catch (err) {
return err;
}
}
test("fail works in a try/catch", () => {
const result = invokeWithTry(() => expect().fail("expected failure")); // Erroneously passes
expect(result).toBeUndefined(); // Actually fails here b/c `result` is a `JestAssertionError`
});
What you did:
I passed a callback containing expect().fail()
to a function that invokes the callback in a try/catch
block.
What happened (please provide anything you think will help):
The failure was not registered since the catch
intercepted the JestAssertionError
raised by the fail
matcher.
Reproduction repository (if possible): https://github.com/thehale/jest-extended-fail-not-working-in-try-catch
Metadata
Metadata
Assignees
Labels
No labels