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/components/UsersTableItem/UserTableItem.test.tsx from Jest to Vitest #2926

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(MOCKS2, true);
const link3 = new StaticMockLink(MOCKS_UPDATE, true);
import useLocalStorage from 'utils/useLocalstorage';
import {
REMOVE_ADMIN_MUTATION,
palisadoes marked this conversation as resolved.
Show resolved Hide resolved
REMOVE_MEMBER_MUTATION,
} from 'GraphQl/Mutations/mutations';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
import type * as RouterTypes from 'react-router-dom';

const { setItem } = useLocalStorage();

Expand All @@ -28,29 +26,34 @@ async function wait(ms = 100): Promise<void> {
});
});
}
const resetAndRefetchMock = jest.fn();
const resetAndRefetchMock = vi.fn();

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

Object.defineProperty(window, 'location', {
value: {
replace: jest.fn(),
replace: vi.fn(),
},
writable: true,
});

const mockNavgatePush = jest.fn();
const mockNavgatePush = vi.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockNavgatePush,
}));
vi.mock('react-router-dom', async () => {
const actual = (await vi.importActual(
'react-router-dom',
)) as typeof RouterTypes;
return {
...actual,
useNavigate: () => mockNavgatePush,
};
});

beforeEach(() => {
setItem('SuperAdmin', true);
Expand All @@ -59,11 +62,11 @@ beforeEach(() => {

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

describe('Testing User Table Item', () => {
console.error = jest.fn((message) => {
console.error = vi.fn((message) => {
if (message.includes('validateDOMNesting')) {
return;
}
Expand Down Expand Up @@ -1183,25 +1186,6 @@ describe('Testing User Table Item', () => {
resetAndRefetch: resetAndRefetchMock,
};

const mocks = [
{
request: {
query: REMOVE_MEMBER_MUTATION,
variables: {
userId: '123',
orgId: 'xyz',
},
},
palisadoes marked this conversation as resolved.
Show resolved Hide resolved
result: {
errors: [
{
message: 'User does not exist',
},
],
},
},
];

render(
<MockedProvider addTypename={false} link={link2}>
<BrowserRouter>
Expand Down
Loading