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: src/screens/OrganizationTags/OrganizationTags.test.tsx from Jest to Vitest #3078

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
waitForElementToBeRemoved,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import 'jest-location-mock';
import { vi } from 'vitest';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
Expand Down Expand Up @@ -44,10 +44,10 @@ async function wait(ms = 500): 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 @@ -77,14 +77,17 @@ const renderOrganizationTags = (link: ApolloLink): RenderResult => {

describe('Organisation Tags Page', () => {
beforeEach(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: 'orgId' }),
}));
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useParams: () => ({ orgId: 'orgId' }),
};
});
});

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

Expand Down Expand Up @@ -129,7 +132,6 @@ describe('Organisation Tags Page', () => {
screen.queryByTestId('closeCreateTagModal'),
);
});

test('navigates to sub tags screen after clicking on a tag', async () => {
renderOrganizationTags(link);

Expand Down
12 changes: 6 additions & 6 deletions src/screens/OrganizationTags/OrganizationTagsMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: '' } },
sortedBy: { id: 'DESCENDING' },
Expand Down Expand Up @@ -187,7 +187,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
after: '10',
where: { name: { starts_with: '' } },
Expand Down Expand Up @@ -248,7 +248,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: 'searchUserTag' } },
sortedBy: { id: 'DESCENDING' },
Expand Down Expand Up @@ -322,7 +322,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: 'searchUserTag' } },
sortedBy: { id: 'ASCENDING' },
Expand Down Expand Up @@ -397,7 +397,7 @@ export const MOCKS = [
query: CREATE_USER_TAG,
variables: {
name: 'userTag 12',
organizationId: '123',
organizationId: 'orgId',
},
},
result: {
Expand All @@ -415,7 +415,7 @@ export const MOCKS_ERROR = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: '' } },
sortedBy: { id: 'DESCENDING' },
Expand Down
Loading