@@ -8,6 +8,10 @@ import type { Span, SpanAttributes } from '@sentry/core';
8
8
import type { Route } from '../src/router' ;
9
9
import { instrumentVueRouter } from '../src/router' ;
10
10
11
+ const MOCK_SPAN = {
12
+ spanContext : ( ) => ( { traceId : '1234' , spanId : '5678' } ) ,
13
+ } ;
14
+
11
15
const captureExceptionSpy = vi . spyOn ( SentryBrowser , 'captureException' ) ;
12
16
vi . mock ( '@sentry/core' , async ( ) => {
13
17
const actual = await vi . importActual ( '@sentry/core' ) ;
@@ -76,7 +80,7 @@ describe('instrumentVueRouter()', () => {
76
80
} ) ;
77
81
78
82
it ( 'should return instrumentation that instruments VueRouter.onError' , ( ) => {
79
- const mockStartSpan = vi . fn ( ) ;
83
+ const mockStartSpan = vi . fn ( ) . mockReturnValue ( MOCK_SPAN ) ;
80
84
instrumentVueRouter (
81
85
mockVueRouter ,
82
86
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -103,7 +107,7 @@ describe('instrumentVueRouter()', () => {
103
107
] ) (
104
108
'should return instrumentation that instruments VueRouter.beforeEach(%s, %s) for navigations' ,
105
109
( fromKey , toKey , transactionName , transactionSource ) => {
106
- const mockStartSpan = vi . fn ( ) ;
110
+ const mockStartSpan = vi . fn ( ) . mockReturnValue ( MOCK_SPAN ) ;
107
111
instrumentVueRouter (
108
112
mockVueRouter ,
109
113
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -143,7 +147,8 @@ describe('instrumentVueRouter()', () => {
143
147
'should return instrumentation that instruments VueRouter.beforeEach(%s, %s) for pageloads' ,
144
148
( fromKey , toKey , transactionName , transactionSource ) => {
145
149
const mockRootSpan = {
146
- getSpanJSON : vi . fn ( ) . mockReturnValue ( { op : 'pageload' } ) ,
150
+ ...MOCK_SPAN ,
151
+ getSpanJSON : vi . fn ( ) . mockReturnValue ( { op : 'pageload' , data : { } } ) ,
147
152
updateName : vi . fn ( ) ,
148
153
setAttribute : vi . fn ( ) ,
149
154
setAttributes : vi . fn ( ) ,
@@ -183,7 +188,7 @@ describe('instrumentVueRouter()', () => {
183
188
) ;
184
189
185
190
it ( 'allows to configure routeLabel=path' , ( ) => {
186
- const mockStartSpan = vi . fn ( ) ;
191
+ const mockStartSpan = vi . fn ( ) . mockReturnValue ( MOCK_SPAN ) ;
187
192
instrumentVueRouter (
188
193
mockVueRouter ,
189
194
{ routeLabel : 'path' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -211,7 +216,7 @@ describe('instrumentVueRouter()', () => {
211
216
} ) ;
212
217
213
218
it ( 'allows to configure routeLabel=name' , ( ) => {
214
- const mockStartSpan = vi . fn ( ) ;
219
+ const mockStartSpan = vi . fn ( ) . mockReturnValue ( MOCK_SPAN ) ;
215
220
instrumentVueRouter (
216
221
mockVueRouter ,
217
222
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation : true } ,
@@ -240,6 +245,7 @@ describe('instrumentVueRouter()', () => {
240
245
241
246
it ( "doesn't overwrite a pageload transaction name it was set to custom before the router resolved the route" , ( ) => {
242
247
const mockRootSpan = {
248
+ ...MOCK_SPAN ,
243
249
updateName : vi . fn ( ) ,
244
250
setAttribute : vi . fn ( ) ,
245
251
setAttributes : vi . fn ( ) ,
@@ -294,9 +300,7 @@ describe('instrumentVueRouter()', () => {
294
300
} ) ;
295
301
296
302
it ( "updates the scope's `transactionName` when a route is resolved" , ( ) => {
297
- const mockStartSpan = vi . fn ( ) . mockImplementation ( _ => {
298
- return { } ;
299
- } ) ;
303
+ const mockStartSpan = vi . fn ( ) . mockReturnValue ( MOCK_SPAN ) ;
300
304
301
305
const scopeSetTransactionNameSpy = vi . fn ( ) ;
302
306
@@ -329,6 +333,7 @@ describe('instrumentVueRouter()', () => {
329
333
'should return instrumentation that considers the instrumentPageLoad = %p' ,
330
334
( instrumentPageLoad , expectedCallsAmount ) => {
331
335
const mockRootSpan = {
336
+ ...MOCK_SPAN ,
332
337
updateName : vi . fn ( ) ,
333
338
setData : vi . fn ( ) ,
334
339
setAttribute : vi . fn ( ) ,
@@ -367,7 +372,7 @@ describe('instrumentVueRouter()', () => {
367
372
] ) (
368
373
'should return instrumentation that considers the instrumentNavigation = %p' ,
369
374
( instrumentNavigation , expectedCallsAmount ) => {
370
- const mockStartSpan = vi . fn ( ) ;
375
+ const mockStartSpan = vi . fn ( ) . mockReturnValue ( MOCK_SPAN ) ;
371
376
instrumentVueRouter (
372
377
mockVueRouter ,
373
378
{ routeLabel : 'name' , instrumentPageLoad : true , instrumentNavigation } ,
@@ -386,7 +391,7 @@ describe('instrumentVueRouter()', () => {
386
391
) ;
387
392
388
393
it ( "doesn't throw when `next` is not available in the beforeEach callback (Vue Router 4)" , ( ) => {
389
- const mockStartSpan = vi . fn ( ) ;
394
+ const mockStartSpan = vi . fn ( ) . mockReturnValue ( MOCK_SPAN ) ;
390
395
instrumentVueRouter (
391
396
mockVueRouter ,
392
397
{ routeLabel : 'path' , instrumentPageLoad : true , instrumentNavigation : true } ,
0 commit comments