Skip to content

Commit

Permalink
Refactored src/screens/FundCampaignPledge/PledgeModal from jest to vi…
Browse files Browse the repository at this point in the history
…test (#3450)
  • Loading branch information
syedali237 authored Jan 27, 2025
1 parent 151ae10 commit 1a43332
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ import { toast } from 'react-toastify';
import type { InterfacePledgeModal } from './PledgeModal';
import PledgeModal from './PledgeModal';
import React from 'react';
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(),
},
}));

jest.mock('@mui/x-date-pickers/DateTimePicker', () => {
vi.mock('@mui/x-date-pickers/DesktopDateTimePicker', async () => {
const actual = await vi.importActual(
'@mui/x-date-pickers/DesktopDateTimePicker',
);
return {
DateTimePicker: jest.requireActual(
'@mui/x-date-pickers/DesktopDateTimePicker',
).DesktopDateTimePicker,
DateTimePicker: actual.DesktopDateTimePicker,
};
});

Expand All @@ -45,7 +47,7 @@ const translations = JSON.parse(
const pledgeProps: InterfacePledgeModal[] = [
{
isOpen: true,
hide: jest.fn(),
hide: vi.fn(),
pledge: {
_id: '1',
amount: 100,
Expand All @@ -61,15 +63,15 @@ const pledgeProps: InterfacePledgeModal[] = [
},
],
},
refetchPledge: jest.fn(),
refetchPledge: vi.fn(),
campaignId: 'campaignId',
orgId: 'orgId',
endDate: new Date(),
mode: 'create',
},
{
isOpen: true,
hide: jest.fn(),
hide: vi.fn(),
pledge: {
_id: '1',
amount: 100,
Expand All @@ -85,7 +87,7 @@ const pledgeProps: InterfacePledgeModal[] = [
},
],
},
refetchPledge: jest.fn(),
refetchPledge: vi.fn(),
campaignId: 'campaignId',
orgId: 'orgId',
endDate: new Date(),
Expand Down Expand Up @@ -113,14 +115,18 @@ const renderPledgeModal = (

describe('PledgeModal', () => {
beforeAll(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: 'orgId', fundCampaignId: 'fundCampaignId' }),
}));
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useParams: () => ({ orgId: 'orgId', fundCampaignId: 'fundCampaignId' }),
useNavigate: vi.fn(),
};
});
});

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

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/UserPortal/Campaigns/PledgeModal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vi.mock('react-toastify', () => ({
},
}));

vi.mock('@mui/x-date-pickers/DateTimePicker', async () => {
vi.mock('@mui/x-date-pickers/DesktopDateTimePicker', async () => {
const { DesktopDateTimePicker } = await vi.importActual(
'@mui/x-date-pickers/DesktopDateTimePicker',
);
Expand Down

0 comments on commit 1a43332

Please sign in to comment.