Skip to content

Commit d8dd265

Browse files
authored
test(react): Remove duplicated test mock (#20200)
The `getActiveSpan` mock calls `actual.getActiveSpan()` and immediately assigns to the returned span without guarding against `undefined`. When the router subscriber fires outside an active span context, `span` is `undefined` and the property assignment throws a TypeError. Additionally, there are two `vi.mock('@sentry/core')` declarations for the same module; the first (lines 66-73) is dead code since the second one overrides it. Closes #20199
1 parent a641812 commit d8dd265

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

packages/react/test/reactrouter-cross-usage.test.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@ vi.mock('@sentry/browser', async requireActual => {
6363
};
6464
});
6565

66-
vi.mock('@sentry/core', async requireActual => {
67-
return {
68-
...(await requireActual()),
69-
getRootSpan: () => {
70-
return mockRootSpan;
71-
},
72-
};
73-
});
74-
7566
vi.mock('@sentry/core', async requireActual => {
7667
const actual = (await requireActual()) as any;
7768
return {
@@ -82,6 +73,8 @@ vi.mock('@sentry/core', async requireActual => {
8273
getActiveSpan: () => {
8374
const span = actual.getActiveSpan();
8475

76+
if (!span) return undefined;
77+
8578
span.updateName = mockNavigationSpan.updateName;
8679
span.setAttribute = mockNavigationSpan.setAttribute;
8780

0 commit comments

Comments
 (0)