Skip to content

Commit afb83e0

Browse files
authored
test(remix): Add an integration test for client-side click errors. (#12606)
Added a test for the case mentioned in #10455 The last frame of the stack trace seems to be correct on the latest version.
1 parent 1064443 commit afb83e0

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Throw error on click
2+
export default function ClickError() {
3+
return (
4+
<div>
5+
<button
6+
onClick={() => {
7+
throw new Error('ClickError');
8+
}}
9+
id="click-error"
10+
>
11+
Throw error on click
12+
</button>
13+
</div>
14+
);
15+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect, test } from '@playwright/test';
2+
import { Event } from '@sentry/types';
3+
import { getMultipleSentryEnvelopeRequests } from './utils/helpers';
4+
5+
const useV2 = process.env.REMIX_VERSION === '2';
6+
7+
test('should report a manually captured message on click with the correct stacktrace.', async ({ page }) => {
8+
if (!useV2) {
9+
test.skip();
10+
return;
11+
}
12+
13+
await page.goto('/click-error');
14+
15+
const promise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
16+
await page.click('#click-error');
17+
18+
const envelopes = await promise;
19+
20+
const [_, errorEnvelope] = envelopes;
21+
22+
expect(errorEnvelope.level).toBe('error');
23+
expect(errorEnvelope.sdk?.name).toBe('sentry.javascript.remix');
24+
25+
expect(errorEnvelope.exception?.values).toMatchObject([
26+
{
27+
type: 'Error',
28+
value: 'ClickError',
29+
stacktrace: { frames: expect.any(Array) },
30+
mechanism: { type: 'instrument', handled: false },
31+
},
32+
]);
33+
34+
// Check the last frame of the stacktrace
35+
const stacktrace = errorEnvelope.exception?.values[0]?.stacktrace?.frames;
36+
37+
expect(stacktrace?.[stacktrace.length - 1].function).toBe('onClick');
38+
});

0 commit comments

Comments
 (0)