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/OrganizationEvents.tsx from Jest to Vitest #2559 #3013

Merged
Merged
Changes from 6 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
Expand Up @@ -9,7 +9,6 @@
} from '@testing-library/react';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import 'jest-location-mock';
import { I18nextProvider } from 'react-i18next';

import OrganizationEvents from './OrganizationEvents';
Expand All @@ -23,14 +22,31 @@
import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { MOCKS } from './OrganizationEventsMocks';

import { describe, test, expect, vi } from 'vitest';
const theme = createTheme({
palette: {
primary: {
main: '#31bb6b',
},
},
});
Object.defineProperty(window, 'location', {
value: {
href: 'http://localhost/',
assign: vi.fn((url) => {
const urlObj = new URL(url, 'http://localhost');
window.location.href = urlObj.href;
window.location.pathname = urlObj.pathname;
window.location.search = urlObj.search;
window.location.hash = urlObj.hash;
}),
reload: vi.fn(),
pathname: '/',
search: '',
hash: '',
origin: 'http://localhost',
},
});

const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink([], true);
Expand All @@ -42,7 +58,6 @@
});
});
}

const translations = {
...JSON.parse(
JSON.stringify(
Expand All @@ -53,19 +68,19 @@
...JSON.parse(JSON.stringify(i18n.getDataByLanguage('en')?.errors ?? {})),
};

jest.mock('@mui/x-date-pickers/DateTimePicker', () => {
vi.mock('@mui/x-date-pickers/DateTimePicker', () => {
return {
DateTimePicker: jest.requireActual(
DateTimePicker: vi.requireActual(

Check failure on line 73 in src/screens/OrganizationEvents/OrganizationEvents.spec.tsx

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Property 'requireActual' does not exist on type 'VitestUtils'.
'@mui/x-date-pickers/DesktopDateTimePicker',
).DesktopDateTimePicker,
};
});

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

Expand All @@ -80,7 +95,7 @@
endTime: '05:00 PM',
};

global.alert = jest.fn();
global.alert = vi.fn();

test('It is necessary to query the correct mock data.', async () => {
const dataQuery1 = MOCKS[0]?.result?.data?.eventsByOrganizationConnection;
Expand Down Expand Up @@ -148,7 +163,7 @@
expect(container.textContent).not.toBe('Loading data...');
await wait();
expect(container.textContent).toMatch('Month');
expect(window.location).toBeAt('/orglist');
expect(window.location.pathname).toBe('/orglist');
});

test('No mock data', async () => {
Expand Down
Loading