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

Refactor from jest to vitest #2483 #3139

Closed
Show file tree
Hide file tree
Changes from all 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
92 changes: 66 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.7",
"@babel/preset-typescript": "^7.26.0",
"@eslint/eslintrc": "^3.2.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^12.1.10",
"@testing-library/dom": "^10.4.0",
"@types/inquirer": "^9.0.7",
"@types/jest": "^26.0.24",
"@types/js-cookie": "^3.0.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { vi, expect, describe, it } from 'vitest';
import { MockedProvider } from '@apollo/react-testing';
import type { RenderResult } from '@testing-library/react';
import {
Expand All @@ -10,7 +11,7 @@ import {
} from '@testing-library/react';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import 'jest-location-mock';

import { I18nextProvider } from 'react-i18next';

import { store } from 'state/store';
Expand All @@ -34,10 +35,10 @@ async function wait(): Promise<void> {
});
}

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

Expand Down Expand Up @@ -114,19 +115,25 @@ const renderAddPeopleToTagModal = (

describe('Organisation Tags Page', () => {
beforeEach(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: 'orgId' }),
}));
cache.reset();
// Mocking `react-router-dom` to return the actual module and override `useParams`
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom'); // Import the actual module
return {
...actual,
useParams: () => ({ orgId: '1', tagId: '1' }), // Mock `useParams` to return a custom object
};
});

// Reset any necessary cache or mocks
vi.clearAllMocks(); // Clear all mocks to ensure a clean state before each test
});

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
cleanup();
});

test('Component loads correctly', async () => {
it('Component loads correctly', async () => {
const { getByText } = renderAddPeopleToTagModal(props, link);

await wait();
Expand All @@ -136,7 +143,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Renders error component when when query is unsuccessful', async () => {
it('Renders error component when when query is unsuccessful', async () => {
const { queryByText } = renderAddPeopleToTagModal(props, link2);

await wait();
Expand All @@ -146,7 +153,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Selects and deselects members to assign to', async () => {
it('Selects and deselects members to assign to', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -174,7 +181,7 @@ describe('Organisation Tags Page', () => {
userEvent.click(screen.getAllByTestId('deselectMemberBtn')[0]);
});

test('searchs for tags where the firstName matches the provided firstName search input', async () => {
it('searchs for tags where the firstName matches the provided firstName search input', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -207,7 +214,7 @@ describe('Organisation Tags Page', () => {
});
});

test('searchs for tags where the lastName matches the provided lastName search input', async () => {
it('searchs for tags where the lastName matches the provided lastName search input', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -240,7 +247,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Renders more members with infinite scroll', async () => {
it('Renders more members with infinite scroll', async () => {
const { getByText } = renderAddPeopleToTagModal(props, link);

await wait();
Expand Down Expand Up @@ -269,7 +276,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Toasts error when no one is selected while assigning', async () => {
it('Toasts error when no one is selected while assigning', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand All @@ -284,7 +291,7 @@ describe('Organisation Tags Page', () => {
});
});

test('Assigns tag to multiple people', async () => {
it('Assigns tag to multiple people', async () => {
renderAddPeopleToTagModal(props, link);

await wait();
Expand Down
Loading