From aac146643130111534096a6a669027d2fda5ea7c Mon Sep 17 00:00:00 2001 From: Aadhil Ahamed Date: Thu, 26 Dec 2024 20:33:23 +0530 Subject: [PATCH] Refactored src/components/Venues/VenueModal.test.tsx from Jest to Vitest #2827 (#2932) --- ...enueModal.test.tsx => VenueModal.spec.tsx} | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) rename src/components/Venues/{VenueModal.test.tsx => VenueModal.spec.tsx} (93%) diff --git a/src/components/Venues/VenueModal.test.tsx b/src/components/Venues/VenueModal.spec.tsx similarity index 93% rename from src/components/Venues/VenueModal.test.tsx rename to src/components/Venues/VenueModal.spec.tsx index b299c8ff20..45560c40cb 100644 --- a/src/components/Venues/VenueModal.test.tsx +++ b/src/components/Venues/VenueModal.spec.tsx @@ -4,7 +4,6 @@ import type { RenderResult } from '@testing-library/react'; import { render, screen, fireEvent } from '@testing-library/react'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; -import 'jest-location-mock'; import { I18nextProvider } from 'react-i18next'; import type { InterfaceVenueModalProps } from './VenueModal'; @@ -19,6 +18,8 @@ import { UPDATE_VENUE_MUTATION, } from 'GraphQl/Mutations/mutations'; import type { ApolloLink } from '@apollo/client'; +import { vi } from 'vitest'; +import type * as RouterTypes from 'react-router-dom'; const MOCKS = [ { @@ -65,10 +66,16 @@ const MOCKS = [ const link = new StaticMockLink(MOCKS, true); const mockId = 'orgId'; -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useParams: () => ({ orgId: mockId }), -})); + +vi.mock('react-router-dom', async () => { + const actual = (await vi.importActual( + 'react-router-dom', + )) as typeof RouterTypes; + return { + ...actual, + useParams: () => ({ orgId: mockId }), + }; +}); async function wait(ms = 100): Promise { await act(() => { @@ -78,26 +85,26 @@ async function wait(ms = 100): Promise { }); } -jest.mock('react-toastify', () => ({ +vi.mock('react-toastify', () => ({ toast: { - success: jest.fn(), - warning: jest.fn(), - error: jest.fn(), + success: vi.fn(), + warning: vi.fn(), + error: vi.fn(), }, })); const props: InterfaceVenueModalProps[] = [ { show: true, - onHide: jest.fn(), + onHide: vi.fn(), edit: false, venueData: null, - refetchVenues: jest.fn(), + refetchVenues: vi.fn(), orgId: 'orgId', }, { show: true, - onHide: jest.fn(), + onHide: vi.fn(), edit: true, venueData: { _id: 'venue1', @@ -106,7 +113,7 @@ const props: InterfaceVenueModalProps[] = [ image: 'image1', capacity: '100', }, - refetchVenues: jest.fn(), + refetchVenues: vi.fn(), orgId: 'orgId', }, ]; @@ -129,7 +136,7 @@ const renderVenueModal = ( }; describe('VenueModal', () => { - global.alert = jest.fn(); + global.alert = vi.fn(); test('renders correctly when show is true', async () => { renderVenueModal(props[0], link);