Skip to content

Commit 4b5315a

Browse files
committed
Simulate window.onerror in rethrow tests.
1 parent b220ff2 commit 4b5315a

File tree

1 file changed

+29
-8
lines changed
  • dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown

1 file changed

+29
-8
lines changed

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@ sentryTest(
1111

1212
await page.goto(url);
1313

14-
const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 1);
14+
const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
1515

1616
runScriptInSandbox(page, {
1717
content: `
18-
try {
19-
foo();
20-
} catch (e) {
21-
Sentry.captureException(e);
22-
throw e;
23-
}
24-
`,
18+
try {
19+
try {
20+
foo();
21+
} catch (e) {
22+
Sentry.captureException(e);
23+
throw e; // intentionally re-throw
24+
}
25+
} catch (e) {
26+
// simulate window.onerror without generating a Script error
27+
window.onerror('error', 'file.js', 1, 1, e);
28+
}
29+
30+
Sentry.captureException(new Error('error 2'));
31+
`,
2532
});
2633

2734
const events = await errorEventsPromise;
@@ -39,5 +46,19 @@ sentryTest(
3946
frames: expect.any(Array),
4047
},
4148
});
49+
50+
// This is not a refernece error, but another generic error
51+
expect(events[1].exception?.values).toHaveLength(1);
52+
expect(events[1].exception?.values?.[0]).toMatchObject({
53+
type: 'Error',
54+
value: 'error 2',
55+
mechanism: {
56+
type: 'generic',
57+
handled: true,
58+
},
59+
stacktrace: {
60+
frames: expect.any(Array),
61+
},
62+
});
4263
},
4364
);

0 commit comments

Comments
 (0)