Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate src/screens/UserPortal/Donate/Donate.test.tsx Tests from Jest to Vitest #2636

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/**
* Unit tests for the Donate component.
*
* This file contains tests for the Donate component to ensure it behaves as expected
* under various scenarios.
*/
import React, { act } from 'react';
import { render, screen } from '@testing-library/react';
import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';

import { vi } from 'vitest';
import {
ORGANIZATION_DONATION_CONNECTION_LIST,
USER_ORGANIZATION_CONNECTION,
Expand Down Expand Up @@ -132,35 +138,35 @@ async function wait(ms = 100): Promise<void> {
});
}

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: '' }),
vi.mock('react-router-dom', async () => ({
...(await vi.importActual('react-router-dom')),
useParams: vi.fn(() => ({ orgId: '' })),
}));

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

describe('Testing Donate Screen [User Portal]', () => {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});

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

test('Screen should be rendered properly', async () => {
Expand Down
Loading