Skip to content

Commit

Permalink
test: added test for hook useBotIdInternal #132 (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianez authored Oct 6, 2024
1 parent 3a0204b commit e892df2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions __tests__/hooks/userBotIdInternal.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit e892df2

Please sign in to comment.