From 20f01899df3b4982a6c758cb2f2eae0f5c0eb1d4 Mon Sep 17 00:00:00 2001 From: Millian Lamiaux Date: Mon, 13 Jul 2026 16:11:15 +0200 Subject: [PATCH] fix(test): resolve unhandled rejection in sidebar logout error test The 'should handle logout errors gracefully' test mocked supabase.auth.signOut to reject (throw), which does not match real supabase-js behaviour (signOut resolves with { error }, never throws). The rejecting mock caused an unhandled promise rejection in the async handleLogout onClick handler: tolerated locally (vitest exit 0) but failing in CI (npx vitest run exits 1). Switch to a realistic resolved-with-error mock and assert the user is still redirected to /login (true graceful handling). No production code change. --- admin-web/components/sidebar.test.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/admin-web/components/sidebar.test.tsx b/admin-web/components/sidebar.test.tsx index 2863498..377db62 100644 --- a/admin-web/components/sidebar.test.tsx +++ b/admin-web/components/sidebar.test.tsx @@ -91,8 +91,10 @@ describe('Sidebar', () => { }) it('should handle logout errors gracefully', async () => { - mockSignOut.mockRejectedValueOnce(new Error('Network error')) - + // Real supabase.auth.signOut() never throws — it resolves with { error }. + // Mocking it realistically avoids an unhandled rejection and matches prod behaviour. + mockSignOut.mockResolvedValueOnce({ error: new Error('Network error') }) + render() const logoutButton = screen.getByRole('button', { name: /logout/i }) @@ -101,6 +103,9 @@ describe('Sidebar', () => { await waitFor(() => { expect(mockSignOut).toHaveBeenCalled() }) + + // Graceful: even when signOut errors, the user is still redirected to login. + expect(mockPush).toHaveBeenCalledWith('/login') }) it('should have correct styling for navigation', () => {