From 627e2105f882e8f66ffcfef15ad9d7e5e0e6f575 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 12 Feb 2023 01:13:26 +0200 Subject: [PATCH] should call onLoginError with error if authentication fails --- tests/hooks/useTuitioClient.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/hooks/useTuitioClient.test.ts b/tests/hooks/useTuitioClient.test.ts index c91c7b0..38e934b 100644 --- a/tests/hooks/useTuitioClient.test.ts +++ b/tests/hooks/useTuitioClient.test.ts @@ -82,6 +82,25 @@ describe("useTuitioClient", () => { ); }); + it("should call onLoginError with error if authentication fails", async () => { + (TuitioClient as jest.Mocked).mockImplementation(() => ({ + authenticate: jest.fn().mockRejectedValue(new Error("Login failed")) + })); + + const onLoginError = jest.fn(); + const { result } = renderHook(() => + useTuitioClient({ onLoginSuccess: jest.fn(), onLoginFailed: jest.fn(), onLoginError }) + ); + + await act(async () => { + try { + await result.current.login("user", "password"); + } catch (error) { + expect(onLoginError).toHaveBeenCalledWith(error); + } + }); + }); + it("should call invalidate when logout is called", () => { const { result } = renderHook(() => useTuitioClient({