Browse Source

test(rr6): Assign browserHistory to the same mocks as router (#82582)

Evan Purkhiser 2 months ago
parent
commit
f222d5f303

+ 2 - 1
static/app/views/dashboards/orgDashboards.spec.tsx

@@ -237,7 +237,8 @@ describe('OrgDashboards', () => {
       {router: initialData.router}
     );
 
-    expect(browserHistory.replace).not.toHaveBeenCalled();
+    // The first call is done by the page filters
+    expect(initialData.router.replace).not.toHaveBeenCalledTimes(2);
   });
 
   it('does not add query params for page filters if none are saved', () => {

+ 10 - 0
tests/js/sentry-test/reactTestingLibrary.tsx

@@ -12,6 +12,7 @@ import {GlobalDrawer} from 'sentry/components/globalDrawer';
 import GlobalModal from 'sentry/components/globalModal';
 import type {InjectedRouter} from 'sentry/types/legacyReactRouter';
 import type {Organization} from 'sentry/types/organization';
+import {DANGEROUS_SET_TEST_HISTORY} from 'sentry/utils/browserHistory';
 import {QueryClientProvider} from 'sentry/utils/queryClient';
 import {lightTheme} from 'sentry/utils/theme';
 import {OrganizationContext} from 'sentry/views/organizationContext';
@@ -104,6 +105,15 @@ function makeAllTheProviders(options: ProviderOptions) {
       };
     }
 
+    DANGEROUS_SET_TEST_HISTORY({
+      goBack: router.goBack,
+      push: router.push,
+      replace: router.replace,
+      listen: jest.fn(() => {}),
+      listenBefore: jest.fn(),
+      getCurrentLocation: jest.fn(() => ({pathname: '', query: {}})),
+    });
+
     // By default react-router 6 catches exceptions and displays the stack
     // trace. For tests we want them to bubble out
     function ErrorBoundary(): React.ReactNode {