Skip to content

Commit

Permalink
fix testing error on leage all page
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-nowicki committed Oct 16, 2024
1 parent d1b7c32 commit 7b35b78
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions app/(main)/league/all/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { toast } from 'react-hot-toast';
import Alert from '@/components/AlertNotification/AlertNotification';
import { AlertVariants } from '@/components/AlertNotification/Alerts.enum';
import { mock } from 'node:test';

const mockUseAuthContext = {
isSignedIn: false,
Expand Down Expand Up @@ -269,22 +270,26 @@ describe('Leagues Component', () => {
survivors: [],
};

const updateUser = jest.fn();
const updateUserLeagues = jest.fn();
const updateAllLeagues = jest.fn();
const updateGameWeek = jest.fn();
const updateEntries = jest.fn();

mockUseDataStore.mockReturnValue({
user,
allLeagues: [league],
updateUser,
updateUserLeagues,
userLeagues: [],
updateAllLeagues,
updateGameWeek,
updateEntries,
});

mockGetUserLeagues.mockResolvedValueOnce([]);
mockGetAllLeagues.mockResolvedValueOnce([league]);
mockAddUserToLeague.mockResolvedValue(
Promise.resolve({
userDocumentId: user.documentId,
selectedLeague: league.leagueId,
selectedLeagues: [league.leagueId],
participants: [user.id],
survivors: [user.id],
}),
);
mockAddUserToLeague.mockRejectedValue(new Error());

render(<Leagues />);

Expand All @@ -297,14 +302,6 @@ describe('Leagues Component', () => {
fireEvent.click(screen.getByTestId('join-league-button'));

await waitFor(() => {
expect(mockAddUserToLeague).toHaveBeenCalledWith({
userDocumentId: user.documentId,
selectedLeague: league.leagueId,
selectedLeagues: [league.leagueId],
participants: [user.id],
survivors: [user.id],
});

expect(toast.custom).toHaveBeenCalledWith(
<Alert
variant={AlertVariants.Error}
Expand Down

0 comments on commit 7b35b78

Please sign in to comment.