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 Jest to Vitest #2828 #2873

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,6 +11,7 @@ import { BrowserRouter } from 'react-router-dom';
const link = new StaticMockLink(MOCKS, true);
import useLocalStorage from 'utils/useLocalstorage';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';

const { setItem } = useLocalStorage();

Expand All @@ -21,13 +22,13 @@ 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(),
},
}));

Expand All @@ -37,17 +38,17 @@ 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;
}
console.warn(message);
});
test('Should render props and text elements test for the page component', async () => {
it('Should render props and text elements it for the page component', async () => {
const props: {
request: InterfaceRequestsListItem;
index: number;
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('Testing User Table Item', () => {
expect(screen.getByText(/[email protected]/i)).toBeInTheDocument();
});

test('Accept MembershipRequest Button works properly', async () => {
it('Accept MembershipRequest Button works properly', async () => {
const props: {
request: InterfaceRequestsListItem;
index: number;
Expand Down Expand Up @@ -113,7 +114,39 @@ describe('Testing User Table Item', () => {
userEvent.click(screen.getByTestId('acceptMembershipRequestBtn123'));
});

test('Reject MembershipRequest Button works properly', async () => {
it('Accept MembershipRequest handles error', async () => {
const props: {
request: InterfaceRequestsListItem;
index: number;
resetAndRefetch: () => void;
} = {
request: {
_id: '1',
user: {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
},
},
index: 1,
resetAndRefetch: resetAndRefetchMock,
};

render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<RequestsTableItem {...props} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);

await wait();
userEvent.click(screen.getByTestId('acceptMembershipRequestBtn1'));
});

it('Reject MembershipRequest Button works properly', async () => {
const props: {
request: InterfaceRequestsListItem;
index: number;
Expand Down Expand Up @@ -144,4 +177,36 @@ describe('Testing User Table Item', () => {
await wait();
userEvent.click(screen.getByTestId('rejectMembershipRequestBtn123'));
});

it('Reject MembershipRequest handles error', async () => {
const props: {
request: InterfaceRequestsListItem;
index: number;
resetAndRefetch: () => void;
} = {
request: {
_id: '1',
user: {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
},
},
index: 1,
resetAndRefetch: resetAndRefetchMock,
};

render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<RequestsTableItem {...props} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);

await wait();
userEvent.click(screen.getByTestId('rejectMembershipRequestBtn1'));
});
});
8 changes: 4 additions & 4 deletions src/components/RequestsTableItem/RequestsTableItemMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export const MOCKS = [
request: {
query: ACCEPT_ORGANIZATION_REQUEST_MUTATION,
variables: {
id: '1',
id: '123',
},
},
result: {
data: {
acceptMembershipRequest: {
_id: '1',
_id: '123',
},
},
},
Expand All @@ -23,13 +23,13 @@ export const MOCKS = [
request: {
query: REJECT_ORGANIZATION_REQUEST_MUTATION,
variables: {
id: '1',
id: '123',
},
},
result: {
data: {
rejectMembershipRequest: {
_id: '1',
_id: '123',
},
},
},
Expand Down
Loading