From 7c2aab9e6b01b9fc67ad3fe5055265f337827a7d Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Tue, 23 Apr 2024 12:34:18 +0100 Subject: [PATCH] Simulate `window.onerror` in rethrow tests. --- .../instrumentation/onError/rethrown/test.ts | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts index a796b9c0d208..a6d96dbc935f 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts +++ b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts @@ -11,17 +11,24 @@ sentryTest( await page.goto(url); - const errorEventsPromise = getMultipleSentryEnvelopeRequests(page, 1); + const errorEventsPromise = getMultipleSentryEnvelopeRequests(page, 2); runScriptInSandbox(page, { content: ` - try { - foo(); - } catch (e) { - Sentry.captureException(e); - throw e; - } - `, + try { + try { + foo(); + } catch (e) { + Sentry.captureException(e); + throw e; // intentionally re-throw + } + } catch (e) { + // simulate window.onerror without generating a Script error + window.onerror('error', 'file.js', 1, 1, e); + } + + Sentry.captureException(new Error('error 2')); + `, }); const events = await errorEventsPromise; @@ -39,5 +46,19 @@ sentryTest( frames: expect.any(Array), }, }); + + // This is not a refernece error, but another generic error + expect(events[1].exception?.values).toHaveLength(1); + expect(events[1].exception?.values?.[0]).toMatchObject({ + type: 'Error', + value: 'error 2', + mechanism: { + type: 'generic', + handled: true, + }, + stacktrace: { + frames: expect.any(Array), + }, + }); }, );