Skip to content

Commit a9d534b

Browse files
committed
fix vue router test
1 parent 2536f5d commit a9d534b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

packages/vue/test/router.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import type { Span, SpanAttributes } from '@sentry/core';
88
import type { Route } from '../src/router';
99
import { instrumentVueRouter } from '../src/router';
1010

11+
const MOCK_SPAN = {
12+
spanContext: () => ({ traceId: '1234', spanId: '5678' }),
13+
};
14+
1115
const captureExceptionSpy = vi.spyOn(SentryBrowser, 'captureException');
1216
vi.mock('@sentry/core', async () => {
1317
const actual = await vi.importActual('@sentry/core');
@@ -76,7 +80,7 @@ describe('instrumentVueRouter()', () => {
7680
});
7781

7882
it('should return instrumentation that instruments VueRouter.onError', () => {
79-
const mockStartSpan = vi.fn();
83+
const mockStartSpan = vi.fn().mockReturnValue(MOCK_SPAN);
8084
instrumentVueRouter(
8185
mockVueRouter,
8286
{ routeLabel: 'name', instrumentPageLoad: true, instrumentNavigation: true },
@@ -103,7 +107,7 @@ describe('instrumentVueRouter()', () => {
103107
])(
104108
'should return instrumentation that instruments VueRouter.beforeEach(%s, %s) for navigations',
105109
(fromKey, toKey, transactionName, transactionSource) => {
106-
const mockStartSpan = vi.fn();
110+
const mockStartSpan = vi.fn().mockReturnValue(MOCK_SPAN);
107111
instrumentVueRouter(
108112
mockVueRouter,
109113
{ routeLabel: 'name', instrumentPageLoad: true, instrumentNavigation: true },
@@ -143,7 +147,8 @@ describe('instrumentVueRouter()', () => {
143147
'should return instrumentation that instruments VueRouter.beforeEach(%s, %s) for pageloads',
144148
(fromKey, toKey, transactionName, transactionSource) => {
145149
const mockRootSpan = {
146-
getSpanJSON: vi.fn().mockReturnValue({ op: 'pageload' }),
150+
...MOCK_SPAN,
151+
getSpanJSON: vi.fn().mockReturnValue({ op: 'pageload', data: {} }),
147152
updateName: vi.fn(),
148153
setAttribute: vi.fn(),
149154
setAttributes: vi.fn(),
@@ -183,7 +188,7 @@ describe('instrumentVueRouter()', () => {
183188
);
184189

185190
it('allows to configure routeLabel=path', () => {
186-
const mockStartSpan = vi.fn();
191+
const mockStartSpan = vi.fn().mockReturnValue(MOCK_SPAN);
187192
instrumentVueRouter(
188193
mockVueRouter,
189194
{ routeLabel: 'path', instrumentPageLoad: true, instrumentNavigation: true },
@@ -211,7 +216,7 @@ describe('instrumentVueRouter()', () => {
211216
});
212217

213218
it('allows to configure routeLabel=name', () => {
214-
const mockStartSpan = vi.fn();
219+
const mockStartSpan = vi.fn().mockReturnValue(MOCK_SPAN);
215220
instrumentVueRouter(
216221
mockVueRouter,
217222
{ routeLabel: 'name', instrumentPageLoad: true, instrumentNavigation: true },
@@ -240,6 +245,7 @@ describe('instrumentVueRouter()', () => {
240245

241246
it("doesn't overwrite a pageload transaction name it was set to custom before the router resolved the route", () => {
242247
const mockRootSpan = {
248+
...MOCK_SPAN,
243249
updateName: vi.fn(),
244250
setAttribute: vi.fn(),
245251
setAttributes: vi.fn(),
@@ -294,9 +300,7 @@ describe('instrumentVueRouter()', () => {
294300
});
295301

296302
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);
300304

301305
const scopeSetTransactionNameSpy = vi.fn();
302306

@@ -329,6 +333,7 @@ describe('instrumentVueRouter()', () => {
329333
'should return instrumentation that considers the instrumentPageLoad = %p',
330334
(instrumentPageLoad, expectedCallsAmount) => {
331335
const mockRootSpan = {
336+
...MOCK_SPAN,
332337
updateName: vi.fn(),
333338
setData: vi.fn(),
334339
setAttribute: vi.fn(),
@@ -367,7 +372,7 @@ describe('instrumentVueRouter()', () => {
367372
])(
368373
'should return instrumentation that considers the instrumentNavigation = %p',
369374
(instrumentNavigation, expectedCallsAmount) => {
370-
const mockStartSpan = vi.fn();
375+
const mockStartSpan = vi.fn().mockReturnValue(MOCK_SPAN);
371376
instrumentVueRouter(
372377
mockVueRouter,
373378
{ routeLabel: 'name', instrumentPageLoad: true, instrumentNavigation },
@@ -386,7 +391,7 @@ describe('instrumentVueRouter()', () => {
386391
);
387392

388393
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);
390395
instrumentVueRouter(
391396
mockVueRouter,
392397
{ routeLabel: 'path', instrumentPageLoad: true, instrumentNavigation: true },

0 commit comments

Comments
 (0)