should call onLoginError with error if authentication fails

master
Tudor Stanciu 2023-02-12 01:13:26 +02:00
parent c7a1a465ff
commit 627e2105f8
1 changed files with 19 additions and 0 deletions

View File

@ -82,6 +82,25 @@ describe("useTuitioClient", () => {
);
});
it("should call onLoginError with error if authentication fails", async () => {
(TuitioClient as jest.Mocked<any>).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({