Skip to content

Commit

Permalink
Refactored Pledges tests from Jest to Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
khushipatil1523 committed Jan 10, 2025
1 parent 308d64c commit 0f9c1df
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions src/screens/UserPortal/Pledges/Pledge.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ vi.mock('react-toastify', () => ({
}));
vi.mock('@mui/x-date-pickers/DateTimePicker', async () => {
const actualModule = await vi.importActual(
'@mui/x-date-pickers/DesktopDateTimePicker'
'@mui/x-date-pickers/DesktopDateTimePicker',
);
return {
DateTimePicker: actualModule.DesktopDateTimePicker,
Expand Down Expand Up @@ -82,8 +82,6 @@ describe('Testing User Pledge Screen', () => {
setItem('userId', 'userId');
});



afterAll(() => {
vi.clearAllMocks();
});
Expand All @@ -110,38 +108,38 @@ describe('Testing User Pledge Screen', () => {
});

// This test works:
it('should redirect to fallback URL if userId is null in LocalStorage', async () => {
setItem('userId', null);

renderMyPledges(link1);
await waitFor(() => {
expect(screen.getByTestId('paramsError')).toBeInTheDocument();
it('should redirect to fallback URL if userId is null in LocalStorage', async () => {
setItem('userId', null);

renderMyPledges(link1);
await waitFor(() => {
expect(screen.getByTestId('paramsError')).toBeInTheDocument();
});
});
});

// So let's structure our failing test similarly:
it('should redirect to fallback URL if URL params are undefined', async () => {
const customRender = render(
// So let's structure our failing test similarly:
it('should redirect to fallback URL if URL params are undefined', async () => {
render(
<MockedProvider addTypename={false} link={link1}>
<MemoryRouter initialEntries={['/']}>
<Provider store={store}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<I18nextProvider i18n={i18nForTest}>
<Routes>
<Route path="/user/pledges/:orgId" element={<Pledges />} />
<Route path="/" element={<div data-testid="paramsError" />} />
</Routes>
</I18nextProvider>
</LocalizationProvider>
</Provider>
</MemoryRouter>
</MockedProvider>
);
<MemoryRouter initialEntries={['/']}>
<Provider store={store}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<I18nextProvider i18n={i18nForTest}>
<Routes>
<Route path="/user/pledges/:orgId" element={<Pledges />} />
<Route path="/" element={<div data-testid="paramsError" />} />
</Routes>
</I18nextProvider>
</LocalizationProvider>
</Provider>
</MemoryRouter>
</MockedProvider>,
);

await waitFor(() => {
await waitFor(() => {
expect(screen.getByTestId('paramsError')).toBeInTheDocument();
});
});
});

it('check if user image renders', async () => {
renderMyPledges(link1);
Expand Down

0 comments on commit 0f9c1df

Please sign in to comment.