Skip to content

Commit

Permalink
migrate errorHandler tests from Jest to Vitest (#2927)
Browse files Browse the repository at this point in the history
* migrate errorHandler tests from Jest to Vitest #2758

* Deleted src/utils/errorHandler.test.tsx
  • Loading branch information
Dhiren-Mhatre authored Dec 26, 2024
1 parent aa9c903 commit a630a91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('Testing Organization Dashboard Screen', () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);

// Wait for initial load
// First wait for the dashboard to fully load
await waitFor(() => {
expect(screen.getByText(t.upcomingEvents)).toBeInTheDocument();
});
Expand All @@ -160,12 +160,8 @@ describe('Testing Organization Dashboard Screen', () => {
expect(screen.getByText(t.events)).toBeInTheDocument();
expect(screen.getByText(t.blockedUsers)).toBeInTheDocument();

// Upcoming events - Using more flexible matcher
await waitFor(() => {
expect(
screen.getByText(/Event 1/i, { exact: false }),
).toBeInTheDocument();
});
// Upcoming events - Use a more flexible matcher
expect(screen.getByText(/Event 1/i, { exact: false })).toBeInTheDocument();

// Latest posts
expect(screen.getByText(t.latestPosts)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ type TFunction = (key: string, options?: Record<string, unknown>) => string;

import { errorHandler } from './errorHandler';
import { toast } from 'react-toastify';
import { describe, it, expect, vi } from 'vitest';

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

Expand All @@ -22,7 +23,7 @@ describe('Test if errorHandler is working properly', () => {
};

beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it('should call toast.error with the correct message if error message is "Failed to fetch"', async () => {
Expand Down

0 comments on commit a630a91

Please sign in to comment.