Skip to content

Commit

Permalink
Simulate window.onerror in rethrow tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Apr 25, 2024
1 parent d3d3596 commit 7c2aab9
Showing 1 changed file with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ sentryTest(

await page.goto(url);

const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 1);
const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(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;
Expand All @@ -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),
},
});
},
);

0 comments on commit 7c2aab9

Please sign in to comment.