@@ -48,10 +48,12 @@ describe('callbacks', () => {
48
48
let transaction : Transaction ;
49
49
const alwaysCreateSpan = ( ) => true ;
50
50
const neverCreateSpan = ( ) => false ;
51
+ const startTimestamp = 1356996072000 ;
52
+ const endTimestamp = 1356996072000 ;
51
53
const fetchHandlerData : FetchData = {
52
54
args : [ 'http://dogs.are.great/' , { } ] ,
53
55
fetchData : { url : 'http://dogs.are.great/' , method : 'GET' } ,
54
- startTimestamp : 1356996072000 ,
56
+ startTimestamp,
55
57
} ;
56
58
const xhrHandlerData : XHRData = {
57
59
xhr : {
@@ -66,9 +68,8 @@ describe('callbacks', () => {
66
68
// setRequestHeader: XMLHttpRequest.prototype.setRequestHeader,
67
69
setRequestHeader,
68
70
} ,
69
- startTimestamp : 1353501072000 ,
71
+ startTimestamp,
70
72
} ;
71
- const endTimestamp = 1356996072000 ;
72
73
73
74
beforeAll ( ( ) => {
74
75
hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
@@ -263,5 +264,26 @@ describe('callbacks', () => {
263
264
264
265
expect ( newSpan ! . status ) . toBe ( spanStatusfromHttpCode ( 404 ) ) ;
265
266
} ) ;
267
+
268
+ it ( 'ignores response with no associated span' , ( ) => {
269
+ // the request might be missed somehow. E.g. if it was sent before tracing gets enabled.
270
+
271
+ const postRequestXHRHandlerData = {
272
+ ...{
273
+ xhr : {
274
+ __sentry_xhr__ : xhrHandlerData . xhr . __sentry_xhr__ ,
275
+ } ,
276
+ } ,
277
+ startTimestamp,
278
+ endTimestamp,
279
+ } ;
280
+
281
+ // in that case, the response coming back will be ignored
282
+ xhrCallback ( postRequestXHRHandlerData , alwaysCreateSpan , { } ) ;
283
+
284
+ const newSpan = transaction . spanRecorder ?. spans [ 1 ] ;
285
+
286
+ expect ( newSpan ) . toBeUndefined ( ) ;
287
+ } ) ;
266
288
} ) ;
267
289
} ) ;
0 commit comments