Browse Source

ref(rr6): Set browserHistory to shims in tests (#78419)

Evan Purkhiser 5 months ago
parent
commit
547a6b05e5
2 changed files with 15 additions and 15 deletions
  1. 4 0
      static/app/utils/browserHistory.tsx
  2. 11 15
      tests/js/setup.ts

+ 4 - 0
static/app/utils/browserHistory.tsx

@@ -84,3 +84,7 @@ export function DANGEROUS_SET_REACT_ROUTER_6_HISTORY(router: Router) {
 
   browserHistory = compat6BrowserHistory;
 }
+
+export function DANGEROUS_SET_TEST_HISTORY(router: any) {
+  browserHistory = router as any;
+}

+ 11 - 15
tests/js/setup.ts

@@ -14,6 +14,7 @@ import {resetMockDate} from 'sentry-test/utils';
 import type {Client} from 'sentry/__mocks__/api';
 import {DEFAULT_LOCALE_DATA, setLocale} from 'sentry/locale';
 import ConfigStore from 'sentry/stores/configStore';
+import {DANGEROUS_SET_TEST_HISTORY} from 'sentry/utils/browserHistory';
 import * as performanceForSentry from 'sentry/utils/performanceForSentry';
 
 window.__SENTRY_USING_REACT_ROUTER_SIX = true;
@@ -69,22 +70,17 @@ jest
   .spyOn(performanceForSentry, 'VisuallyCompleteWithData')
   .mockImplementation(props => props.children as ReactElement);
 jest.mock('scroll-to-element', () => jest.fn());
-jest.mock('react-router', function reactRouterMockFactory() {
-  const ReactRouter = jest.requireActual('react-router');
-  return {
-    ...ReactRouter,
-    browserHistory: {
-      goBack: jest.fn(),
-      push: jest.fn(),
-      replace: jest.fn(),
-      listen: jest.fn(() => {}),
-      listenBefore: jest.fn(),
-      getCurrentLocation: jest.fn(() => ({pathname: '', query: {}})),
-    },
-  };
-});
 jest.mock('sentry/utils/search/searchBoxTextArea');
 
+DANGEROUS_SET_TEST_HISTORY({
+  goBack: jest.fn(),
+  push: jest.fn(),
+  replace: jest.fn(),
+  listen: jest.fn(() => {}),
+  listenBefore: jest.fn(),
+  getCurrentLocation: jest.fn(() => ({pathname: '', query: {}})),
+});
+
 jest.mock('react-virtualized', function reactVirtualizedMockFactory() {
   const ActualReactVirtualized = jest.requireActual('react-virtualized');
   return {
@@ -135,7 +131,7 @@ jest.mock('@sentry/react', function sentryReact() {
       set: jest.fn(),
       distribution: jest.fn(),
     },
-    reactRouterV3BrowserTracingIntegration: jest.fn().mockReturnValue({}),
+    reactRouterV6BrowserTracingIntegration: jest.fn().mockReturnValue({}),
     browserTracingIntegration: jest.fn().mockReturnValue({}),
     browserProfilingIntegration: jest.fn().mockReturnValue({}),
     addEventProcessor: jest.fn(),