@@ -2215,19 +2215,33 @@ describe('Client', () => {
2215
2215
await expect ( promise ) . resolves . toEqual ( result ) ;
2216
2216
} ) ;
2217
2217
2218
- // This test is skipped because jest keeps retrying ad infinitum
2219
- // when encountering an unhandled rejections.
2220
- // We could set "NODE_OPTIONS='--unhandled-rejections=warn' but it
2221
- // would affect the entire test suite.
2222
- // Maybe this can be re-enabled when switching to vitest.
2223
- //
2224
- // eslint-disable-next-line @sentry-internal/sdk/no-skipped-tests
2225
- test . skip ( 'handles asynchronous errors' , async ( ) => {
2218
+ test ( 'handles asynchronous errors without causing unhandled rejection' , async ( ) => {
2226
2219
const error = new Error ( 'Test error' ) ;
2227
2220
const callback = vi . fn ( ) . mockRejectedValue ( error ) ;
2228
2221
2229
- const promise = await withMonitor ( 'test-monitor' , callback ) ;
2222
+ const promise = withMonitor ( 'test-monitor' , callback ) ;
2230
2223
await expect ( promise ) . rejects . toThrowError ( error ) ;
2231
2224
} ) ;
2225
+
2226
+ test ( 'handles promise rejection without causing unhandled rejection' , async ( ) => {
2227
+ const error = new Error ( 'Promise rejection' ) ;
2228
+ const promise = withMonitor ( 'test-monitor' , ( ) => Promise . reject ( error ) ) ;
2229
+
2230
+ await expect ( promise ) . rejects . toThrow ( error ) ;
2231
+ } ) ;
2232
+
2233
+ test ( 'propagates promise values correctly' , async ( ) => {
2234
+ const promise = withMonitor ( 'test-monitor' , ( ) => Promise . resolve ( 'resolved value' ) ) ;
2235
+ await expect ( promise ) . resolves . toBe ( 'resolved value' ) ;
2236
+ } ) ;
2237
+
2238
+ test ( 'handles nested withMonitor calls correctly' , async ( ) => {
2239
+ const innerError = new Error ( 'Inner error' ) ;
2240
+ const promise = withMonitor ( 'outer-monitor' , ( ) => {
2241
+ return withMonitor ( 'inner-monitor' , ( ) => Promise . reject ( innerError ) ) ;
2242
+ } ) ;
2243
+
2244
+ await expect ( promise ) . rejects . toThrow ( innerError ) ;
2245
+ } ) ;
2232
2246
} ) ;
2233
2247
} ) ;
0 commit comments