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

Refactored src/screens/UserPortal/Campaigns/PledgeModal.test.tsx from jest to vitest #3355

Merged
Merged
Changes from 1 commit
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
@@ -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,
@@ -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,
@@ -81,7 +83,7 @@ const pledgeProps: InterfacePledgeModal[] = [
},
],
},
refetchPledge: jest.fn(),
refetchPledge: vi.fn(),
campaignId: 'campaignId',
userId: 'userId',
endDate: new Date(),
@@ -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(() => {
@@ -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();

Unchanged files with check annotations Beta

await waitFor(
() => {
expect(mockReload).toHaveBeenCalled();

Check failure on line 111 in src/components/UserListCard/UserListCard.spec.tsx

GitHub Actions / Test Application

src/components/UserListCard/UserListCard.spec.tsx > Testing User List Card > Should show success toast and reload page after successful mutation

AssertionError: expected "spy" to be called at least once Ignored nodes: comments, script, style <html> <head /> <body> <div> <button class="_memberfontcreatedbtnUserListCard_658d08 btn btn-primary" type="button" > Add Admin </button> </div> </body> </html> ❯ __vi_import_4__.waitFor.timeout src/components/UserListCard/UserListCard.spec.tsx:111:28 ❯ runWithExpensiveErrorDiagnosticsDisabled node_modules/@testing-library/dom/dist/config.js:47:12 ❯ checkCallback node_modules/@testing-library/dom/dist/wait-for.js:124:77 ❯ Timeout.checkRealTimersCallback node_modules/@testing-library/dom/dist/wait-for.js:118:16
},
{ timeout: DEFAULT_TIMEOUT },
);