Skip to content

Commit

Permalink
refactored src/screens/UserPortal/Campaigns/PledgeModal.test.tsx from…
Browse files Browse the repository at this point in the history
… jest to vitest (#3355)
  • Loading branch information
syedali237 authored Jan 20, 2025
1 parent d739938 commit 0185646
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@ import PledgeModal from './PledgeModal';
import React from 'react';
import { USER_DETAILS } from 'GraphQl/Queries/Queries';
import { CREATE_PlEDGE, UPDATE_PLEDGE } from 'GraphQl/Mutations/PledgeMutation';
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/DateTimePicker', async () => {
const { DesktopDateTimePicker } = await vi.importActual(
'@mui/x-date-pickers/DesktopDateTimePicker',
);
return {
DateTimePicker: jest.requireActual(
'@mui/x-date-pickers/DesktopDateTimePicker',
).DesktopDateTimePicker,
DateTimePicker: DesktopDateTimePicker,
};
});

const pledgeProps: InterfacePledgeModal[] = [
{
isOpen: true,
hide: jest.fn(),
hide: vi.fn(),
pledge: {
_id: '1',
amount: 100,
Expand All @@ -57,15 +59,15 @@ const pledgeProps: InterfacePledgeModal[] = [
},
],
},
refetchPledge: jest.fn(),
refetchPledge: vi.fn(),
campaignId: 'campaignId',
userId: 'userId',
endDate: new Date(),
mode: 'create',
},
{
isOpen: true,
hide: jest.fn(),
hide: vi.fn(),
pledge: {
_id: '1',
amount: 100,
Expand All @@ -81,7 +83,7 @@ const pledgeProps: InterfacePledgeModal[] = [
},
],
},
refetchPledge: jest.fn(),
refetchPledge: vi.fn(),
campaignId: 'campaignId',
userId: 'userId',
endDate: new Date(),
Expand Down Expand Up @@ -210,14 +212,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 Expand Up @@ -300,7 +306,6 @@ describe('PledgeModal', () => {
expect(screen.getByTestId('submitPledgeBtn')).toBeInTheDocument();

fireEvent.click(screen.getByTestId('submitPledgeBtn'));

await waitFor(() => {
expect(toast.success).toHaveBeenCalled();
expect(pledgeProps[0].refetchPledge).toHaveBeenCalled();
Expand Down

0 comments on commit 0185646

Please sign in to comment.