@@ -259,7 +259,7 @@ describe('wrapLoadWithSentry', () => {
259
259
} ;
260
260
} ;
261
261
262
- it . only ( 'creates a fetch span and attaches tracing headers if event.fetch was called' , async ( ) => {
262
+ it ( 'creates a fetch span and attaches tracing headers if event.fetch was called' , async ( ) => {
263
263
const wrappedLoad = wrapLoadWithSentry ( load ) ;
264
264
await wrappedLoad ( MOCK_LOAD_ARGS ) ;
265
265
@@ -279,30 +279,19 @@ describe('wrapLoadWithSentry', () => {
279
279
) ;
280
280
expect ( mockTrace ) . toHaveBeenNthCalledWith ( 2 , spanCtx , expect . any ( Function ) ) ;
281
281
282
- // TODO: refactor
283
- const expectedFetchArgs =
284
- originalFetchArgs . length > 1
285
- ? [
286
- originalFetchArgs [ 0 ] ,
287
- {
288
- ...( originalFetchArgs [ 1 ] as RequestInit ) ,
289
- headers : {
290
- // @ts -ignore that's fine
291
- ...( originalFetchArgs [ 1 ] . headers as RequestInit [ 'headers' ] ) ,
292
- baggage : expect . any ( String ) ,
293
- 'sentry-trace' : expect . any ( String ) ,
294
- } ,
295
- } ,
296
- ]
297
- : [
298
- originalFetchArgs [ 0 ] ,
299
- {
300
- headers : {
301
- baggage : expect . any ( String ) ,
302
- 'sentry-trace' : expect . any ( String ) ,
303
- } ,
304
- } ,
305
- ] ;
282
+ const hasSecondArg = originalFetchArgs . length > 1 ;
283
+ const expectedFetchArgs = [
284
+ originalFetchArgs [ 0 ] ,
285
+ {
286
+ ...( hasSecondArg && ( originalFetchArgs [ 1 ] as RequestInit ) ) ,
287
+ headers : {
288
+ // @ts -ignore that's fine
289
+ ...( hasSecondArg && ( originalFetchArgs [ 1 ] . headers as RequestInit [ 'headers' ] ) ) ,
290
+ baggage : expect . any ( String ) ,
291
+ 'sentry-trace' : expect . any ( String ) ,
292
+ } ,
293
+ } ,
294
+ ] ;
306
295
307
296
expect ( mockedSveltekitFetch ) . toHaveBeenCalledWith ( ...expectedFetchArgs ) ;
308
297
} ) ;
0 commit comments