jest-plugin-must-assert
jest-plugin-must-assert copied to clipboard
Async try...catch is not properly handled and throws an error where it shouldn't
This perfectly fine jest test fails with jest-plugin-must-assert:
describe("Async Try Catch", () => {
it('should work', async () => {
try {
await Promise.reject('whoop')
} catch (e) {
console.log('error catched')
}
expect(true).toBe(true)
})
})
The test works fine when the promise rejection is delayed with setTimeout:
describe("Async Try Catch 2", () => {
it('should work', async () => {
try {
await new Promise((_, reject) => {
setTimeout(() => reject('whoop'))
})
} catch (e) {
console.log('error catched')
}
expect(true).toBe(true)
})
})
This was especially hard to debug because I was initially using mockRejectedValue(...) in a jest test.