Skip to content

Commit 708bac4

Browse files
authored
test: Add DOM events breadcrumbHint test (getsentry#2468)
1 parent 69f66fd commit 708bac4

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

packages/browser/test/integration/common/init.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ var originalBuiltIns = {
1616
};
1717

1818
var events = [];
19+
var eventHints = [];
1920
var breadcrumbs = [];
21+
var breadcrumbHints = [];
2022

2123
// Oh dear IE10...
2224
var dsn =
@@ -33,11 +35,12 @@ function initSDK() {
3335
attachStacktrace: true,
3436
ignoreErrors: ["ignoreErrorTest"],
3537
blacklistUrls: ["foo.js"],
36-
beforeSend: function(event) {
38+
beforeSend: function(event, eventHint) {
3739
events.push(event);
40+
eventHints.push(eventHint);
3841
return event;
3942
},
40-
beforeBreadcrumb: function(breadcrumb) {
43+
beforeBreadcrumb: function(breadcrumb, breadcrumbHint) {
4144
// Filter console logs as we use them for debugging *a lot* and they are not *that* important
4245
// But allow then if we explicitly say so (for one of integration tests)
4346
if (
@@ -69,6 +72,7 @@ function initSDK() {
6972
}
7073

7174
breadcrumbs.push(breadcrumb);
75+
breadcrumbHints.push(breadcrumbHint);
7276
return breadcrumb;
7377
},
7478
});

packages/browser/test/integration/suites/breadcrumbs.js

+22
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,28 @@ describe("breadcrumbs", function() {
330330
});
331331
});
332332

333+
it("should provide a hint for dom events that includes event name and event itself", function() {
334+
return runInSandbox(sandbox, function() {
335+
var input = document.getElementsByTagName("input")[0];
336+
var clickHandler = function() {};
337+
input.addEventListener("click", clickHandler);
338+
var click = new MouseEvent("click");
339+
input.dispatchEvent(click);
340+
Sentry.captureMessage("test");
341+
}).then(function(summary) {
342+
if (IS_LOADER) {
343+
// The async loader doesn't wrap event listeners, but we should receive the event without breadcrumbs
344+
assert.lengthOf(summary.events, 1);
345+
} else {
346+
assert.equal(summary.breadcrumbHints.length, 1);
347+
assert.equal(summary.breadcrumbHints[0].name, "click");
348+
assert.equal(summary.breadcrumbHints[0].event.target.tagName, "INPUT");
349+
// There should be no expection, if there is one it means we threw it
350+
assert.isUndefined(summary.events[0].exception);
351+
}
352+
});
353+
});
354+
333355
it("should not fail with click or keypress handler with no callback", function() {
334356
return runInSandbox(sandbox, function() {
335357
var input = document.getElementsByTagName("input")[0];

packages/browser/test/integration/suites/helpers.js

+2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function runInSandbox(sandbox, options, code) {
4242
var finalize = function() {
4343
var summary = {
4444
events: events,
45+
eventHints: eventHints,
4546
breadcrumbs: breadcrumbs,
47+
breadcrumbHints: breadcrumbHints,
4648
window: window,
4749
};
4850

0 commit comments

Comments
 (0)