2023-06-30 14:17:38 +03:00
|
|
|
import { act, renderHook } from "@testing-library/react";
|
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
|
|
|
|
import { useLogout } from "../useLogout";
|
|
|
|
|
|
|
|
const mockSignOut = vi.fn(() => ({ error: null }));
|
|
|
|
|
|
|
|
const mockUseSupabase = () => ({
|
|
|
|
supabase: {
|
|
|
|
auth: {
|
|
|
|
signOut: mockSignOut,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
vi.mock("next/navigation", () => ({
|
|
|
|
useRouter: () => ({ replace: vi.fn() }),
|
|
|
|
}));
|
|
|
|
|
|
|
|
vi.mock("@/lib/context/SupabaseProvider", () => ({
|
|
|
|
useSupabase: () => mockUseSupabase(),
|
|
|
|
}));
|
2023-07-18 19:28:44 +03:00
|
|
|
const clearLocalStorageMock = vi.fn();
|
|
|
|
|
|
|
|
Object.defineProperty(window, "localStorage", {
|
|
|
|
value: {
|
|
|
|
clear: clearLocalStorageMock,
|
|
|
|
},
|
|
|
|
});
|
2023-06-30 14:17:38 +03:00
|
|
|
|
|
|
|
describe("useLogout", () => {
|
|
|
|
it("should call signOut", async () => {
|
|
|
|
const { result } = renderHook(() => useLogout());
|
|
|
|
|
|
|
|
await act(() => result.current.handleLogout());
|
|
|
|
|
|
|
|
expect(mockSignOut).toHaveBeenCalledTimes(1);
|
2023-07-18 19:28:44 +03:00
|
|
|
expect(clearLocalStorageMock).toHaveBeenCalledTimes(1);
|
2023-06-30 14:17:38 +03:00
|
|
|
});
|
|
|
|
});
|