Skip to content

Commit a895d35

Browse files
committed
Add integration test for xhr breadcrumbs
1 parent 068f9a7 commit a895d35

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/raven.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ Raven.prototype = {
618618

619619

620620
/**
621-
* Wraps addEventListener to capture breadcrumbs
621+
* Wraps addEventListener to capture UI breadcrumbs
622622
* @param evtName the event name (e.g. "click")
623623
* @param fn the function being wrapped
624624
* @returns {Function}

test/integration/test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,44 @@ describe('integration', function () {
300300
});
301301

302302
describe('breadcrumbs', function () {
303+
304+
it('should record an XMLHttpRequest', function (done) {
305+
var iframe = this.iframe;
306+
307+
iframeExecute(iframe, done,
308+
function () {
309+
310+
// some browsers trigger onpopstate for load / reset breadcrumb state
311+
Raven._breadcrumbs = [];
312+
313+
var xhr = new XMLHttpRequest();
314+
315+
xhr.open('GET', '/test/integration/example.json');
316+
xhr.setRequestHeader('Content-type', 'application/json');
317+
xhr.onreadystatechange = function () {
318+
// don't fire `done` handler until at least *one* onreadystatechange
319+
// has occurred (doesn't actually need to finish)
320+
if (xhr.readyState === 4) {
321+
setTimeout(done);
322+
}
323+
};
324+
xhr.send();
325+
},
326+
function () {
327+
var Raven = iframe.contentWindow.Raven,
328+
breadcrumbs = Raven._breadcrumbs;
329+
330+
assert.equal(breadcrumbs.length, 1);
331+
332+
assert.equal(breadcrumbs[0].type, 'http_request');
333+
assert.equal(breadcrumbs[0].data.method, 'GET');
334+
// NOTE: not checking status code because we seem to get
335+
// statusCode 0/undefined from Phantom when fetching
336+
// example.json (CORS issue?
337+
}
338+
);
339+
});
340+
303341
it('should record a mouse click on element WITH click handler present', function (done) {
304342
var iframe = this.iframe;
305343

0 commit comments

Comments
 (0)