ballercat / ballercat/jest-plugin-must-assert

Async try...catch is not properly handled and throws an error where it shouldn't

Open
#31 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
26
Forks
7
PR merge metrics
No merged PRs in 30d

Description

This perfectly fine jest test fails with `jest-plugin-must-assert`:

```ts
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`:

```ts

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the Jest example with an immediately rejected Promise and compare it with the setTimeout rejection case. The issue does not name a source file or test path, so locate the plugin's async assertion handling and add coverage for both examples. Done means a caught immediate rejection does not produce a spurious error while the assertion still runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.