From 2a90687304daf1911cae06c16e5c17dfb2e93b81 Mon Sep 17 00:00:00 2001 From: Aadhil Ahamed Date: Thu, 26 Dec 2024 18:25:06 +0530 Subject: [PATCH] Refactored src/components/UsersTableItem/UserTableItem.test.tsx from Jest to Vitest #2826 --- ...leItem.test.tsx => UserTableItem.spec.tsx} | 56 +++++++------------ 1 file changed, 20 insertions(+), 36 deletions(-) rename src/components/UsersTableItem/{UserTableItem.test.tsx => UserTableItem.spec.tsx} (98%) diff --git a/src/components/UsersTableItem/UserTableItem.test.tsx b/src/components/UsersTableItem/UserTableItem.spec.tsx similarity index 98% rename from src/components/UsersTableItem/UserTableItem.test.tsx rename to src/components/UsersTableItem/UserTableItem.spec.tsx index 687165b78d..a0b0c39c86 100644 --- a/src/components/UsersTableItem/UserTableItem.test.tsx +++ b/src/components/UsersTableItem/UserTableItem.spec.tsx @@ -13,11 +13,9 @@ const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink(MOCKS2, true); const link3 = new StaticMockLink(MOCKS_UPDATE, true); import useLocalStorage from 'utils/useLocalstorage'; -import { - REMOVE_ADMIN_MUTATION, - REMOVE_MEMBER_MUTATION, -} from 'GraphQl/Mutations/mutations'; import userEvent from '@testing-library/user-event'; +import { vi } from 'vitest'; +import type * as RouterTypes from 'react-router-dom'; const { setItem } = useLocalStorage(); @@ -28,29 +26,34 @@ async function wait(ms = 100): Promise { }); }); } -const resetAndRefetchMock = jest.fn(); +const resetAndRefetchMock = vi.fn(); -jest.mock('react-toastify', () => ({ +vi.mock('react-toastify', () => ({ toast: { - success: jest.fn(), - error: jest.fn(), - warning: jest.fn(), + success: vi.fn(), + error: vi.fn(), + warning: vi.fn(), }, })); Object.defineProperty(window, 'location', { value: { - replace: jest.fn(), + replace: vi.fn(), }, writable: true, }); -const mockNavgatePush = jest.fn(); +const mockNavgatePush = vi.fn(); -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavgatePush, -})); +vi.mock('react-router-dom', async () => { + const actual = (await vi.importActual( + 'react-router-dom', + )) as typeof RouterTypes; + return { + ...actual, + useNavigate: () => mockNavgatePush, + }; +}); beforeEach(() => { setItem('SuperAdmin', true); @@ -59,11 +62,11 @@ beforeEach(() => { afterEach(() => { localStorage.clear(); - jest.clearAllMocks(); + vi.clearAllMocks(); }); describe('Testing User Table Item', () => { - console.error = jest.fn((message) => { + console.error = vi.fn((message) => { if (message.includes('validateDOMNesting')) { return; } @@ -1183,25 +1186,6 @@ describe('Testing User Table Item', () => { resetAndRefetch: resetAndRefetchMock, }; - const mocks = [ - { - request: { - query: REMOVE_MEMBER_MUTATION, - variables: { - userId: '123', - orgId: 'xyz', - }, - }, - result: { - errors: [ - { - message: 'User does not exist', - }, - ], - }, - }, - ]; - render(