From a630a91ad4bbb7368c968ebda621538f51875eb7 Mon Sep 17 00:00:00 2001 From: Dhiren-Mhatre <130587526+Dhiren-Mhatre@users.noreply.github.com> Date: Thu, 26 Dec 2024 19:16:22 +0530 Subject: [PATCH 1/2] migrate errorHandler tests from Jest to Vitest (#2927) * migrate errorHandler tests from Jest to Vitest #2758 * Deleted src/utils/errorHandler.test.tsx --- .../OrganizationDashboard.spec.tsx | 10 +++------- .../{errorHandler.test.tsx => errorHandler.spec.tsx} | 7 ++++--- 2 files changed, 7 insertions(+), 10 deletions(-) rename src/utils/{errorHandler.test.tsx => errorHandler.spec.tsx} (96%) diff --git a/src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx b/src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx index 92404f767b..6fd27ce429 100644 --- a/src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx +++ b/src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx @@ -147,7 +147,7 @@ describe('Testing Organization Dashboard Screen', () => { vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' }); renderOrganizationDashboard(link1); - // Wait for initial load + // First wait for the dashboard to fully load await waitFor(() => { expect(screen.getByText(t.upcomingEvents)).toBeInTheDocument(); }); @@ -160,12 +160,8 @@ describe('Testing Organization Dashboard Screen', () => { expect(screen.getByText(t.events)).toBeInTheDocument(); expect(screen.getByText(t.blockedUsers)).toBeInTheDocument(); - // Upcoming events - Using more flexible matcher - await waitFor(() => { - expect( - screen.getByText(/Event 1/i, { exact: false }), - ).toBeInTheDocument(); - }); + // Upcoming events - Use a more flexible matcher + expect(screen.getByText(/Event 1/i, { exact: false })).toBeInTheDocument(); // Latest posts expect(screen.getByText(t.latestPosts)).toBeInTheDocument(); diff --git a/src/utils/errorHandler.test.tsx b/src/utils/errorHandler.spec.tsx similarity index 96% rename from src/utils/errorHandler.test.tsx rename to src/utils/errorHandler.spec.tsx index f229e8d5fa..96c35e2a7f 100644 --- a/src/utils/errorHandler.test.tsx +++ b/src/utils/errorHandler.spec.tsx @@ -2,10 +2,11 @@ type TFunction = (key: string, options?: Record) => string; import { errorHandler } from './errorHandler'; import { toast } from 'react-toastify'; +import { describe, it, expect, vi } from 'vitest'; -jest.mock('react-toastify', () => ({ +vi.mock('react-toastify', () => ({ toast: { - error: jest.fn(), + error: vi.fn(), }, })); @@ -22,7 +23,7 @@ describe('Test if errorHandler is working properly', () => { }; beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it('should call toast.error with the correct message if error message is "Failed to fetch"', async () => { From 9772f7dcac858a3bcd182b71cc3286ed87e8e0f7 Mon Sep 17 00:00:00 2001 From: Nikhil Raj <125121367+hustlernik@users.noreply.github.com> Date: Thu, 26 Dec 2024 19:21:24 +0530 Subject: [PATCH 2/2] refactor: jest to vitest migration for EditCustomFieldDropDown.test.tsx (#2929) --- ...pDown.test.tsx => EditCustomFieldDropDown.spec.tsx} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename src/components/EditCustomFieldDropDown/{EditCustomFieldDropDown.test.tsx => EditCustomFieldDropDown.spec.tsx} (90%) diff --git a/src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.test.tsx b/src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.spec.tsx similarity index 90% rename from src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.test.tsx rename to src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.spec.tsx index 19d2249a43..4119800dd1 100644 --- a/src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.test.tsx +++ b/src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.spec.tsx @@ -8,6 +8,7 @@ import availableFieldTypes from 'utils/fieldTypes'; import { I18nextProvider } from 'react-i18next'; import i18nForTest from 'utils/i18nForTest'; import type { InterfaceCustomFieldData } from 'utils/interfaces'; +import { describe, it, expect } from 'vitest'; async function wait(ms = 100): Promise { await act(() => { @@ -18,7 +19,7 @@ async function wait(ms = 100): Promise { } describe('Testing Custom Field Dropdown', () => { - test('Component Should be rendered properly', async () => { + it('Component Should be rendered properly', async () => { const customFieldData = { type: 'Number', name: 'Age', @@ -26,11 +27,10 @@ describe('Testing Custom Field Dropdown', () => { const setCustomFieldData: Dispatch< SetStateAction - > = (val) => { - { - val; - } + > = () => { + // Intentionally left blank for testing purposes }; + const props = { customFieldData: customFieldData as InterfaceCustomFieldData, setCustomFieldData: setCustomFieldData,