Skip to content

Commit

Permalink
Refactor: jest to vitest : Fixes PalisadoesFoundation#2547
Browse files Browse the repository at this point in the history
  • Loading branch information
bandhan-majumder committed Dec 12, 2024
1 parent c2630ae commit 80b6f36
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Testing component for managing and displaying Volunteer Membership requests for an event.
*
* This component allows users to view, filter, sort, and create action items. It also allows users to accept or reject volunteer membership requests.
*
*
*/
import React, { act } from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { LocalizationProvider } from '@mui/x-date-pickers';
Expand All @@ -20,11 +27,12 @@ import {
UPDATE_ERROR_MOCKS,
} from './Requests.mocks';
import { toast } from 'react-toastify';
import { vi } from 'vitest';

jest.mock('react-toastify', () => ({
vi.mock('react-toastify', () => ({
toast: {
success: jest.fn(),
error: jest.fn(),
success: vi.fn(),
error: vi.fn(),
},
}));

Expand Down Expand Up @@ -74,14 +82,14 @@ const renderRequests = (link: ApolloLink): RenderResult => {

describe('Testing Requests Screen', () => {
beforeAll(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
vi.mock('react-router-dom', async () => ({
...(await vi.importActual('react-router-dom')),
useParams: () => ({ orgId: 'orgId', eventId: 'eventId' }),
}));
});

afterAll(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it('should redirect to fallback URL if URL params are undefined', async () => {
Expand All @@ -92,10 +100,7 @@ describe('Testing Requests Screen', () => {
<I18nextProvider i18n={i18n}>
<Routes>
<Route path="/event/" element={<Requests />} />
<Route
path="/"
element={<div data-testid="paramsError"></div>}
/>
<Route path="/" element={<Requests />} />
</Routes>
</I18nextProvider>
</Provider>
Expand All @@ -104,7 +109,7 @@ describe('Testing Requests Screen', () => {
);

await waitFor(() => {
expect(screen.getByTestId('paramsError')).toBeInTheDocument();
expect(window.location.pathname).toBe('/');
});
});

Expand Down

0 comments on commit 80b6f36

Please sign in to comment.