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

migration of People.test.tsx from jest to vitest #2661

Open
wants to merge 2 commits into
base: develop-postgres
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 18 additions & 15 deletions src/screens/UserPortal/People/People.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import i18nForTest from 'utils/i18nForTest';
import { StaticMockLink } from 'utils/StaticMockLink';
import People from './People';
import userEvent from '@testing-library/user-event';

import { describe, it, expect, vi } from 'vitest';
const MOCKS = [
{
request: {
Expand Down Expand Up @@ -113,27 +113,30 @@ 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 () => {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useParams: () => ({ orgId: '' }),
};
});

describe('Testing People 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(),
})),
});

test('Screen should be rendered properly', async () => {
it('Screen should be rendered properly', async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -151,7 +154,7 @@ describe('Testing People Screen [User Portal]', () => {
expect(screen.queryAllByText('Noble Mittal')).not.toBe([]);
});

test('Search works properly by pressing enter', async () => {
it('Search works properly by pressing enter', async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -173,7 +176,7 @@ describe('Testing People Screen [User Portal]', () => {
expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument();
});

test('Search works properly by clicking search Btn', async () => {
it('Search works properly by clicking search Btn', async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -199,7 +202,7 @@ describe('Testing People Screen [User Portal]', () => {
expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument();
});

test('Mode is changed to Admins', async () => {
it('Mode is changed to Admins', async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand Down
18 changes: 10 additions & 8 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import { vi, beforeAll } from 'vitest';

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

import { format } from 'util';

Expand All @@ -19,17 +20,18 @@ Object.defineProperty(HTMLMediaElement.prototype, 'muted', {
set: () => ({}),
});

import { jestPreviewConfigure } from 'jest-preview';

// Global CSS here
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/js/bootstrap.min.js';
import 'react-datepicker/dist/react-datepicker.css';
import 'flag-icons/css/flag-icons.min.css';

jestPreviewConfigure({
// Opt-in to automatic mode to preview failed test case automatically.
autoPreview: true,
});
// jestPreviewConfigure({
// // Opt-in to automatic mode to preview failed test case automatically.
// autoPreview: true,
// });

jest.setTimeout(15000);
// Use the global setTimeout function
beforeAll(() => {
vi.setConfig({ testTimeout: 15000 });
});
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
svgrPlugin(),
],
test: {
include: ['src/**/*.spec.{js,jsx,ts,tsx}'],
include: ['src/**/*.spec.{js,jsx,ts,tsx}', 'src/**/*.test.{js,jsx,ts,tsx}'],
globals: true,
environment: 'jsdom',
setupFiles: 'vitest.setup.ts',
Expand Down
Loading