Skip to content

Commit

Permalink
Refactor: src/screens/UserPortal/Volunteer/UpcomingEvents from Jest t…
Browse files Browse the repository at this point in the history
…o Vitest (#2623)

* migrated UpcomingEvents tests from Jest to Vitest

* Rename UpcomingEvents.test.tsx to UpcomingEvents.spec.tsx

* add header comments for UpcomingEvents component tests
  • Loading branch information
abbi4code authored Dec 13, 2024
1 parent 880f6f3 commit f4aafd7
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ import {
} from './UpcomingEvents.mocks';
import { toast } from 'react-toastify';
import useLocalStorage from 'utils/useLocalstorage';
import { vi } from 'vitest';

jest.mock('react-toastify', () => ({
/**
* Unit tests for the UpcomingEvents component.
*
* This file contains tests to verify the functionality and behavior of the UpcomingEvents component
* under various scenarios, including successful data fetching, error handling, and user interactions.
* Mocked dependencies are used to ensure isolated testing of the component.
*/

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

Expand Down Expand Up @@ -81,18 +90,21 @@ const renderUpcomingEvents = (link: ApolloLink): RenderResult => {

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

beforeEach(() => {
setItem('userId', 'userId');
});

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

it('should redirect to fallback URL if URL params are undefined', async () => {
Expand Down

0 comments on commit f4aafd7

Please sign in to comment.