From e892df2062b7f63c0be7bc11b48d737243fdc872 Mon Sep 17 00:00:00 2001 From: Julian Echeverry Date: Sun, 6 Oct 2024 09:27:07 -0500 Subject: [PATCH] test: added test for hook useBotIdInternal #132 (#135) --- __tests__/hooks/userBotIdInternal.test.ts | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 __tests__/hooks/userBotIdInternal.test.ts diff --git a/__tests__/hooks/userBotIdInternal.test.ts b/__tests__/hooks/userBotIdInternal.test.ts new file mode 100644 index 00000000..3365941d --- /dev/null +++ b/__tests__/hooks/userBotIdInternal.test.ts @@ -0,0 +1,27 @@ +import { renderHook } from "@testing-library/react"; +import { expect } from "@jest/globals"; + +import { useBotIdInternal } from "../../src/hooks/internal/useBotIdInternal"; +import { useBotRefsContext } from "../../src/context/BotRefsContext"; + +// Mock the useBotRefsContext +jest.mock("../../src/context/BotRefsContext"); + +// Cast the mock to allow TypeScript to recognize jest mock methods +const mockedUseBotRefsContext = useBotRefsContext as jest.Mock; + +describe("useBotIdInternal", () => { + it("should return the correct botId", () => { + // Mock botIdRef + const botIdRef = { current: "test-bot-id" }; + + // Mock implementation of useBotRefsContext + mockedUseBotRefsContext.mockReturnValue({ botIdRef }); + + // Render the hook + const { result } = renderHook(() => useBotIdInternal()); + + // Call the getBotId method and assert the returned value + expect(result.current.getBotId()).toBe("test-bot-id"); + }); +}); \ No newline at end of file