test: improve mock error handling and add test cleanup

This commit is contained in:
2026-05-14 17:56:35 -07:00
parent 820b1d8d84
commit fea0585a75
3 changed files with 17 additions and 10 deletions
+3 -1
View File
@@ -47,7 +47,9 @@ describe('getSession', () => {
}) })
it('returns null when an error occurs', async () => { it('returns null when an error occurs', async () => {
mockFetch.mockRejectedValue(new Error('Network error')) mockFetch.mockImplementation(async () => {
throw new Error('Network error')
})
const result = await getSession() const result = await getSession()
+6 -1
View File
@@ -3,7 +3,7 @@
* Tests the allowTies field is properly saved when updating tournaments * Tests the allowTies field is properly saved when updating tournaments
*/ */
import { describe, it, expect, mock, beforeEach,} from 'bun:test'; import { describe, it, expect, mock, beforeEach, afterAll } from 'bun:test';
// Create mock functions at module level // Create mock functions at module level
const eventFindUniqueMock = mock(async () => ({})); const eventFindUniqueMock = mock(async () => ({}));
@@ -27,6 +27,11 @@ mock.module('@/lib/permissions', () => ({
canDeleteTournament: canDeleteTournamentMock, canDeleteTournament: canDeleteTournamentMock,
})); }));
// Cleanup after all tests in this file
afterAll(() => {
mock.restore('module');
});
// Import the route handler after mocking // Import the route handler after mocking
import { PUT } from '@/app/api/tournaments/[id]/route'; import { PUT } from '@/app/api/tournaments/[id]/route';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';