11import * as SentryBrowser from '@sentry/browser' ;
22import type { Transaction } from '@sentry/types' ;
3- import { createApp } from 'vue' ;
43
5- import { init , vueRouterInstrumentation } from '../src' ;
4+ import { vueRouterInstrumentation } from '../src' ;
65import type { Route } from '../src/router' ;
76import * as vueTracing from '../src/tracing' ;
87
@@ -171,22 +170,39 @@ describe('vueRouterInstrumentation()', () => {
171170 ) ;
172171
173172 it ( 'allows to configure routeLabel=path' , ( ) => {
174- // Need to setup a proper client with options etc.
175- const app = createApp ( {
176- template : '<div>hello</div>' ,
177- } ) ;
178- const el = document . createElement ( 'div' ) ;
173+ // create instrumentation
174+ const instrument = vueRouterInstrumentation ( mockVueRouter , { routeLabel : 'path' } ) ;
179175
180- init ( {
181- app ,
182- defaultIntegrations : false ,
183- routeLabel : 'path' ,
184- } ) ;
176+ // instrument
177+ instrument ( mockStartTransaction , true , true ) ;
178+
179+ // check
180+ const beforeEachCallback = mockVueRouter . beforeEach . mock . calls [ 0 ] [ 0 ] ;
185181
186- app . mount ( el ) ;
182+ const from = testRoutes . normalRoute1 ;
183+ const to = testRoutes . namedRoute ;
184+ beforeEachCallback ( to , from , mockNext ) ;
187185
186+ // first startTx call happens when the instrumentation is initialized (for pageloads)
187+ expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
188+ name : '/login' ,
189+ metadata : {
190+ source : 'route' ,
191+ } ,
192+ data : {
193+ params : to . params ,
194+ query : to . query ,
195+ } ,
196+ op : 'navigation' ,
197+ tags : {
198+ 'routing.instrumentation' : 'vue-router' ,
199+ } ,
200+ } ) ;
201+ } ) ;
202+
203+ it ( 'allows to configure routeLabel=name' , ( ) => {
188204 // create instrumentation
189- const instrument = vueRouterInstrumentation ( mockVueRouter ) ;
205+ const instrument = vueRouterInstrumentation ( mockVueRouter , { routeLabel : 'name' } ) ;
190206
191207 // instrument
192208 instrument ( mockStartTransaction , true , true ) ;
@@ -200,9 +216,9 @@ describe('vueRouterInstrumentation()', () => {
200216
201217 // first startTx call happens when the instrumentation is initialized (for pageloads)
202218 expect ( mockStartTransaction ) . toHaveBeenLastCalledWith ( {
203- name : '/ login' ,
219+ name : 'login-screen ' ,
204220 metadata : {
205- source : 'route ' ,
221+ source : 'custom ' ,
206222 } ,
207223 data : {
208224 params : to . params ,
0 commit comments