Browse Source

ref(test): Replace `as jest.Mock` with `jest.mocked()` (#71453)

Evan Purkhiser 9 months ago
parent
commit
98016ad987

+ 1 - 1
static/app/components/assigneeSelectorDropdown.spec.tsx

@@ -621,7 +621,7 @@ describe('AssigneeSelectorDropdown', () => {
 
     await userEvent.click(await screen.findByRole('button', {name: 'Invite Member'}));
     expect(openInviteMembersModal).toHaveBeenCalled();
-    (ConfigStore.get as jest.Mock).mockRestore();
+    jest.mocked(ConfigStore.get).mockRestore();
   });
 
   it('renders unassigned', async () => {

+ 1 - 4
static/app/components/charts/onDemandMetricRequest.spec.tsx

@@ -31,7 +31,7 @@ describe('OnDemandMetricRequest', function () {
 
   describe('with props changes', function () {
     beforeAll(function () {
-      (doEventsRequest as jest.Mock).mockImplementation(() =>
+      jest.mocked(doEventsRequest).mockImplementation(() =>
         Promise.resolve({
           isMetricsData: true,
           data: [],
@@ -71,7 +71,6 @@ describe('OnDemandMetricRequest', function () {
       const {rerender} = render(
         <OnDemandMetricRequest {...DEFAULTS}>{mock}</OnDemandMetricRequest>
       );
-      doEventsRequest as jest.Mock;
 
       rerender(
         <OnDemandMetricRequest {...DEFAULTS} project={[123]}>
@@ -92,7 +91,6 @@ describe('OnDemandMetricRequest', function () {
       const {rerender} = render(
         <OnDemandMetricRequest {...DEFAULTS}>{mock}</OnDemandMetricRequest>
       );
-      doEventsRequest as jest.Mock;
 
       rerender(
         <OnDemandMetricRequest {...DEFAULTS} environment={['dev']}>
@@ -113,7 +111,6 @@ describe('OnDemandMetricRequest', function () {
       const {rerender} = render(
         <OnDemandMetricRequest {...DEFAULTS}>{mock}</OnDemandMetricRequest>
       );
-      doEventsRequest as jest.Mock;
 
       rerender(
         <OnDemandMetricRequest {...DEFAULTS} period="7d">

+ 3 - 3
static/app/components/deprecatedAssigneeSelector.spec.tsx

@@ -142,7 +142,7 @@ describe('DeprecatedAssigneeSelector', () => {
       render(<DeprecatedAssigneeSelector id={GROUP_1.id} />);
       jest.spyOn(ConfigStore, 'get').mockImplementation(() => USER_2);
       expect(putSessionUserFirst([USER_1, USER_2])).toEqual([USER_2, USER_1]);
-      (ConfigStore.get as jest.Mock).mockRestore();
+      jest.mocked(ConfigStore.get).mockRestore();
     });
 
     it("should return the same member list if the session user isn't present", () => {
@@ -156,7 +156,7 @@ describe('DeprecatedAssigneeSelector', () => {
       );
 
       expect(putSessionUserFirst([USER_1, USER_2])).toEqual([USER_1, USER_2]);
-      (ConfigStore.get as jest.Mock).mockRestore();
+      jest.mocked(ConfigStore.get).mockRestore();
     });
   });
 
@@ -292,7 +292,7 @@ describe('DeprecatedAssigneeSelector', () => {
 
     await userEvent.click(await screen.findByRole('link', {name: 'Invite Member'}));
     expect(openInviteMembersModal).toHaveBeenCalled();
-    (ConfigStore.get as jest.Mock).mockRestore();
+    jest.mocked(ConfigStore.get).mockRestore();
   });
 
   it('filters user by email and selects with keyboard', async () => {

+ 1 - 1
static/app/components/narrowLayout.spec.tsx

@@ -7,7 +7,7 @@ describe('NarrowLayout', function () {
     jest.spyOn(window.location, 'assign').mockImplementation(() => {});
   });
   afterAll(function () {
-    (window.location.assign as jest.Mock).mockRestore();
+    jest.mocked(window.location.assign).mockRestore();
   });
 
   it('renders without logout', function () {

+ 9 - 9
static/app/components/organizations/pageFilters/container.spec.tsx

@@ -227,9 +227,9 @@ describe('PageFiltersContainer', function () {
       organization
     );
 
-    (globalActions.updateDateTime as jest.Mock).mockClear();
-    (globalActions.updateProjects as jest.Mock).mockClear();
-    (globalActions.updateEnvironments as jest.Mock).mockClear();
+    jest.mocked(globalActions.updateDateTime).mockClear();
+    jest.mocked(globalActions.updateProjects).mockClear();
+    jest.mocked(globalActions.updateEnvironments).mockClear();
 
     rerender(<PageFiltersContainer />);
 
@@ -736,8 +736,8 @@ describe('PageFiltersContainer', function () {
       beforeEach(function () {
         ProjectsStore.loadInitialData(initialData.projects);
 
-        (initialData.router.push as jest.Mock).mockClear();
-        (initialData.router.replace as jest.Mock).mockClear();
+        jest.mocked(initialData.router.push).mockClear();
+        jest.mocked(initialData.router.replace).mockClear();
       });
 
       it('uses first project in org projects when mounting', function () {
@@ -810,8 +810,8 @@ describe('PageFiltersContainer', function () {
 
       beforeEach(function () {
         ProjectsStore.loadInitialData(initialData.projects);
-        (initialData.router.push as jest.Mock).mockClear();
-        (initialData.router.replace as jest.Mock).mockClear();
+        jest.mocked(initialData.router.push).mockClear();
+        jest.mocked(initialData.router.replace).mockClear();
       });
 
       it('appends projectId to URL when mounted with `forceProject`', function () {
@@ -876,8 +876,8 @@ describe('PageFiltersContainer', function () {
       beforeEach(function () {
         ProjectsStore.loadInitialData(initialData.projects);
 
-        (initialData.router.push as jest.Mock).mockClear();
-        (initialData.router.replace as jest.Mock).mockClear();
+        jest.mocked(initialData.router.push).mockClear();
+        jest.mocked(initialData.router.replace).mockClear();
       });
 
       it('does not use first project in org projects when mounting (and without localStorage data)', function () {

+ 1 - 1
static/app/components/search/sources/formSource.spec.tsx

@@ -38,7 +38,7 @@ describe('FormSource', function () {
   });
 
   afterEach(function () {
-    (ActionCreators.loadSearchMap as jest.Mock).mockRestore();
+    jest.mocked(ActionCreators.loadSearchMap).mockRestore();
   });
 
   it('can find a form field', async function () {

+ 1 - 1
static/app/components/stream/group.spec.tsx

@@ -39,7 +39,7 @@ describe('StreamGroup', function () {
   });
 
   afterEach(function () {
-    (trackAnalytics as jest.Mock).mockClear();
+    jest.mocked(trackAnalytics).mockClear();
     GroupStore.reset();
   });
 

+ 2 - 2
static/app/views/issueDetails/groupEventDetails/groupEventDetails.spec.tsx

@@ -343,7 +343,7 @@ describe('groupEventDetails', () => {
 
   afterEach(function () {
     MockApiClient.clearMockResponses();
-    (browserHistory.replace as jest.Mock).mockClear();
+    jest.mocked(browserHistory.replace).mockClear();
   });
 
   it('redirects on switching to an invalid environment selection for event', async function () {
@@ -544,7 +544,7 @@ describe('EventCause', () => {
 
   afterEach(function () {
     MockApiClient.clearMockResponses();
-    (browserHistory.replace as jest.Mock).mockClear();
+    jest.mocked(browserHistory.replace).mockClear();
   });
 
   it('renders suspect commit', async function () {

+ 2 - 2
static/app/views/sentryAppExternalInstallation/index.spec.tsx

@@ -154,7 +154,7 @@ describe('SentryAppExternalInstallation', () => {
         );
       });
 
-      (window.location.assign as jest.Mock).mockClear();
+      jest.mocked(window.location.assign).mockClear();
     });
 
     it('installs and redirects with state', async () => {
@@ -201,7 +201,7 @@ describe('SentryAppExternalInstallation', () => {
         );
       });
 
-      (window.location.assign as jest.Mock).mockClear();
+      jest.mocked(window.location.assign).mockClear();
     });
   });
 

+ 1 - 1
static/app/views/settings/account/accountSecurity/index.spec.tsx

@@ -38,7 +38,7 @@ describe('AccountSecurity', function () {
   });
 
   afterEach(function () {
-    (window.location.assign as jest.Mock).mockRestore();
+    jest.mocked(window.location.assign).mockRestore();
   });
 
   function renderComponent() {

Some files were not shown because too many files changed in this diff