@@ -359,7 +359,7 @@ describe('Hub', () => {
359
359
// TODO the way we dig out the headers to test them doesn't work on Node < 10
360
360
testOnlyIfNodeVersionAtLeast ( 10 ) (
361
361
'should propagate positive sampling decision to child transactions in XHR header' ,
362
- ( ) => {
362
+ async ( ) => {
363
363
const hub = new Hub (
364
364
new BrowserClient ( {
365
365
dsn :
'https://[email protected] /1121' ,
@@ -375,13 +375,12 @@ describe('Hub', () => {
375
375
} ) ;
376
376
377
377
const request = new XMLHttpRequest ( ) ;
378
- request . open ( 'GET' , '/chase-partners' ) ;
379
- request . send ( ) ;
380
-
381
- // mock a response having been received successfully (we have to do it in this roundabout way because readyState
382
- // is readonly and changing it doesn't trigger a readystatechange event)
383
- Object . defineProperty ( request , 'readyState' , { value : 4 } ) ;
384
- request . dispatchEvent ( new Event ( 'readystatechange' ) ) ;
378
+ await new Promise ( resolve => {
379
+ request . timeout = 1 ;
380
+ request . onloadend = request . ontimeout = resolve ;
381
+ request . open ( 'GET' , '/chase-partners' ) ;
382
+ request . send ( '' ) ;
383
+ } ) ;
385
384
386
385
// this looks weird, it's true, but it's really just `request.impl.flag.requestHeaders` - it's just that the
387
386
// `impl` key is a symbol rather than a string, and therefore needs to be referred to by reference rather than
@@ -402,7 +401,7 @@ describe('Hub', () => {
402
401
// TODO the way we dig out the headers to test them doesn't work on Node < 10
403
402
testOnlyIfNodeVersionAtLeast ( 10 ) (
404
403
'should propagate negative sampling decision to child transactions in XHR header' ,
405
- ( ) => {
404
+ async ( ) => {
406
405
const hub = new Hub (
407
406
new BrowserClient ( {
408
407
dsn :
'https://[email protected] /1121' ,
@@ -418,13 +417,12 @@ describe('Hub', () => {
418
417
} ) ;
419
418
420
419
const request = new XMLHttpRequest ( ) ;
421
- request . open ( 'GET' , '/chase-partners' ) ;
422
- request . send ( ) ;
423
-
424
- // mock a response having been received successfully (we have to do it in this roundabout way because readyState
425
- // is readonly and changing it doesn't trigger a readystatechange event)
426
- Object . defineProperty ( request , 'readyState' , { value : 4 } ) ;
427
- request . dispatchEvent ( new Event ( 'readystatechange' ) ) ;
420
+ await new Promise ( resolve => {
421
+ request . timeout = 1 ;
422
+ request . onloadend = request . ontimeout = resolve ;
423
+ request . open ( 'GET' , '/chase-partners' ) ;
424
+ request . send ( '' ) ;
425
+ } ) ;
428
426
429
427
// this looks weird, it's true, but it's really just `request.impl.flag.requestHeaders` - it's just that the
430
428
// `impl` key is a symbol rather than a string, and therefore needs to be referred to by reference rather than
0 commit comments