@@ -359,7 +359,7 @@ describe('Hub', () => {
359359 // TODO the way we dig out the headers to test them doesn't work on Node < 10
360360 testOnlyIfNodeVersionAtLeast ( 10 ) (
361361 'should propagate positive sampling decision to child transactions in XHR header' ,
362- ( ) => {
362+ async ( ) => {
363363 const hub = new Hub (
364364 new BrowserClient ( {
365365 dsn :
'https://[email protected] /1121' , @@ -375,13 +375,12 @@ describe('Hub', () => {
375375 } ) ;
376376
377377 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+ } ) ;
385384
386385 // this looks weird, it's true, but it's really just `request.impl.flag.requestHeaders` - it's just that the
387386 // `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', () => {
402401 // TODO the way we dig out the headers to test them doesn't work on Node < 10
403402 testOnlyIfNodeVersionAtLeast ( 10 ) (
404403 'should propagate negative sampling decision to child transactions in XHR header' ,
405- ( ) => {
404+ async ( ) => {
406405 const hub = new Hub (
407406 new BrowserClient ( {
408407 dsn :
'https://[email protected] /1121' , @@ -418,13 +417,12 @@ describe('Hub', () => {
418417 } ) ;
419418
420419 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+ } ) ;
428426
429427 // this looks weird, it's true, but it's really just `request.impl.flag.requestHeaders` - it's just that the
430428 // `impl` key is a symbol rather than a string, and therefore needs to be referred to by reference rather than
0 commit comments