@@ -53,33 +53,32 @@ Object.defineProperty(global, 'history', { value: dom.window.history, writable:
5353const originalGlobalDocument = WINDOW . document ;
5454const originalGlobalLocation = WINDOW . location ;
5555const originalGlobalHistory = WINDOW . history ;
56- afterAll ( ( ) => {
57- // Clean up JSDom
58- Object . defineProperty ( WINDOW , 'document' , { value : originalGlobalDocument } ) ;
59- Object . defineProperty ( WINDOW , 'location' , { value : originalGlobalLocation } ) ;
60- Object . defineProperty ( WINDOW , 'history' , { value : originalGlobalHistory } ) ;
61- } ) ;
62-
63- afterEach ( ( ) => {
64- vi . useRealTimers ( ) ;
65- performance . clearMarks ( ) ;
66- } ) ;
6756
6857describe ( 'browserTracingIntegration' , ( ) => {
6958 beforeEach ( ( ) => {
59+ vi . useFakeTimers ( ) ;
7060 getCurrentScope ( ) . clear ( ) ;
7161 getIsolationScope ( ) . clear ( ) ;
7262 getCurrentScope ( ) . setClient ( undefined ) ;
7363 document . head . innerHTML = '' ;
64+
65+ const dom = new JSDOM ( undefined , { url : 'https://example.com/' } ) ;
66+ Object . defineProperty ( global , 'location' , { value : dom . window . document . location , writable : true } ) ;
7467 } ) ;
7568
7669 afterEach ( ( ) => {
7770 getActiveSpan ( ) ?. end ( ) ;
71+ vi . useRealTimers ( ) ;
72+ performance . clearMarks ( ) ;
7873 } ) ;
7974
8075 afterAll ( ( ) => {
8176 global . window . TextEncoder = oldTextEncoder ;
8277 global . window . TextDecoder = oldTextDecoder ;
78+ // Clean up JSDom
79+ Object . defineProperty ( WINDOW , 'document' , { value : originalGlobalDocument } ) ;
80+ Object . defineProperty ( WINDOW , 'location' , { value : originalGlobalLocation } ) ;
81+ Object . defineProperty ( WINDOW , 'history' , { value : originalGlobalHistory } ) ;
8382 } ) ;
8483
8584 it ( 'works with tracing enabled' , ( ) => {
@@ -152,7 +151,7 @@ describe('browserTracingIntegration', () => {
152151 expect ( spanIsSampled ( span ! ) ) . toBe ( false ) ;
153152 } ) ;
154153
155- it ( 'starts navigation when URL changes' , ( ) => {
154+ it ( 'starts navigation when URL changes after > 300ms ' , ( ) => {
156155 const client = new BrowserClient (
157156 getDefaultBrowserClientOptions ( {
158157 tracesSampleRate : 1 ,
@@ -185,6 +184,7 @@ describe('browserTracingIntegration', () => {
185184 const dom = new JSDOM ( undefined , { url : 'https://example.com/test' } ) ;
186185 Object . defineProperty ( global , 'location' , { value : dom . window . document . location , writable : true } ) ;
187186
187+ vi . advanceTimersByTime ( 400 ) ;
188188 WINDOW . history . pushState ( { } , '' , '/test' ) ;
189189
190190 expect ( span ! . isRecording ( ) ) . toBe ( false ) ;
0 commit comments