From bbce0c182552c3c04ce15c35f4354b58d3e0d823 Mon Sep 17 00:00:00 2001 From: Devender Singh Date: Tue, 10 Dec 2024 18:40:43 +0530 Subject: [PATCH] refactored: src/screens/OrgSettings from Jest to Vitest(fixes: #2567) --- src/screens/OrgSettings/OrgSettings.spec.tsx | 34 +++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/screens/OrgSettings/OrgSettings.spec.tsx b/src/screens/OrgSettings/OrgSettings.spec.tsx index f7a1891868..19397b7dc7 100644 --- a/src/screens/OrgSettings/OrgSettings.spec.tsx +++ b/src/screens/OrgSettings/OrgSettings.spec.tsx @@ -1,3 +1,4 @@ +import type { ReactElement } from 'react'; import React from 'react'; import { describe, it, expect, vi } from 'vitest'; import { render, screen, waitFor } from '@testing-library/react'; @@ -18,16 +19,24 @@ const link1 = new StaticMockLink(MOCKS); const mockRouterParams = (orgId: string | undefined): void => { vi.doMock('react-router-dom', async () => { - const actual = await vi.importActual('react-router-dom'); - return { - ...actual, - useParams: () => ({ orgId }), - }; + try { + const actual = await vi.importActual('react-router-dom'); + return { + ...actual, + useParams: () => ({ orgId }), + }; + } catch (error) { + console.error('Failed to mock router params:', error); + throw error; + } }); }; -const renderOrganisationSettings = (link = link1, orgId = 'orgId'): void => { +const renderOrganisationSettings = ( + link = link1, + orgId = 'orgId', +): ReturnType => { mockRouterParams(orgId); - render( + return render( @@ -55,7 +64,7 @@ describe('Organisation Settings Page', () => { vi.unmock('react-router-dom'); }); - it('should redirect to fallback URL if URL params are undefined', async () => { + const SetupRedirectTest = async (): Promise => { const useParamsMock = vi.fn(() => ({ orgId: undefined })); vi.doMock('react-router-dom', async () => { const actual = await vi.importActual('react-router-dom'); @@ -64,16 +73,19 @@ describe('Organisation Settings Page', () => { useParams: useParamsMock, }; }); + const orgSettingsModule = await import('./OrgSettings'); + return ; + }; - const { default: OrgSettings } = await import('./OrgSettings'); - + it('should redirect to fallback URL if URL params are undefined', async () => { + const OrgSettings = await SetupRedirectTest(); render( - } /> +