Skip to content

Commit e7e4745

Browse files
bhosmer-antclaude
andcommitted
fix: Fix TypeScript build errors in ToolsTab tests
The previous test implementation caused build failures due to Jest hoisting issues with mock variables. This commit fixes the build by removing mocking in favor of using real schema validation. - Remove jest.mock() of schemaUtils module that caused initialization errors - Add beforeEach to clear schema cache between tests - Use cacheToolOutputSchemas() to set up test scenarios - Let real validation logic run for more accurate tests - All tests pass and build succeeds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b184654 commit e7e4745

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

client/src/components/__tests__/ToolsTab.test.tsx

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
import { render, screen, fireEvent, act } from "@testing-library/react";
2-
import { describe, it, expect, jest } from "@jest/globals";
32
import "@testing-library/jest-dom";
3+
import { describe, it, jest, beforeEach } from "@jest/globals";
44
import ToolsTab from "../ToolsTab";
55
import { Tool } from "@modelcontextprotocol/sdk/types.js";
66
import { Tabs } from "@/components/ui/tabs";
7-
import * as schemaUtils from "@/utils/schemaUtils";
8-
9-
// Mock the schemaUtils module
10-
// Note: hasOutputSchema checks if a tool's output schema validator has been compiled and cached
11-
// by cacheToolOutputSchemas. In these tests, we mock it to avoid needing to call
12-
// cacheToolOutputSchemas for every test that uses tools with output schemas.
13-
// This keeps the tests focused on the component's behavior rather than schema compilation.
14-
jest.mock("@/utils/schemaUtils", () => ({
15-
...jest.requireActual("@/utils/schemaUtils"),
16-
hasOutputSchema: jest.fn(),
17-
validateToolOutput: jest.fn(),
18-
}));
7+
import { cacheToolOutputSchemas } from "@/utils/schemaUtils";
198

209
describe("ToolsTab", () => {
2110
beforeEach(() => {
22-
jest.clearAllMocks();
23-
// Reset to default behavior
24-
(schemaUtils.hasOutputSchema as jest.Mock).mockImplementation(
25-
(toolName) => {
26-
// Only tools with outputSchema property should return true
27-
return false;
28-
},
29-
);
30-
(schemaUtils.validateToolOutput as jest.Mock).mockReturnValue({
31-
isValid: true,
32-
error: null,
33-
});
11+
// Clear the output schema cache before each test
12+
cacheToolOutputSchemas([]);
3413
});
3514

3615
const mockTools: Tool[] = [
@@ -250,8 +229,8 @@ describe("ToolsTab", () => {
250229
};
251230

252231
it("should display structured content when present", () => {
253-
// Mock hasOutputSchema to return true for this tool
254-
(schemaUtils.hasOutputSchema as jest.Mock).mockReturnValue(true);
232+
// Cache the tool's output schema so hasOutputSchema returns true
233+
cacheToolOutputSchemas([toolWithOutputSchema]);
255234

256235
const structuredResult = {
257236
content: [],
@@ -272,13 +251,7 @@ describe("ToolsTab", () => {
272251
});
273252

274253
it("should show validation error for invalid structured content", () => {
275-
// Mock hasOutputSchema to return true for this tool
276-
(schemaUtils.hasOutputSchema as jest.Mock).mockReturnValue(true);
277-
// Mock the validation to fail
278-
(schemaUtils.validateToolOutput as jest.Mock).mockReturnValue({
279-
isValid: false,
280-
error: "temperature must be number",
281-
});
254+
cacheToolOutputSchemas([toolWithOutputSchema]);
282255

283256
const invalidResult = {
284257
content: [],
@@ -296,8 +269,7 @@ describe("ToolsTab", () => {
296269
});
297270

298271
it("should show error when tool with output schema doesn't return structured content", () => {
299-
// Mock hasOutputSchema to return true for this tool
300-
(schemaUtils.hasOutputSchema as jest.Mock).mockReturnValue(true);
272+
cacheToolOutputSchemas([toolWithOutputSchema]);
301273

302274
const resultWithoutStructured = {
303275
content: [{ type: "text", text: "some result" }],
@@ -317,8 +289,7 @@ describe("ToolsTab", () => {
317289
});
318290

319291
it("should show unstructured content title when both structured and unstructured exist", () => {
320-
// Mock hasOutputSchema to return true for this tool
321-
(schemaUtils.hasOutputSchema as jest.Mock).mockReturnValue(true);
292+
cacheToolOutputSchemas([toolWithOutputSchema]);
322293

323294
const resultWithBoth = {
324295
content: [{ type: "text", text: '{"temperature": 25}' }],
@@ -350,8 +321,7 @@ describe("ToolsTab", () => {
350321
});
351322

352323
it("should show compatibility check when tool has output schema", () => {
353-
// Mock hasOutputSchema to return true for this tool
354-
(schemaUtils.hasOutputSchema as jest.Mock).mockReturnValue(true);
324+
cacheToolOutputSchemas([toolWithOutputSchema]);
355325

356326
const compatibleResult = {
357327
content: [{ type: "text", text: '{"temperature": 25}' }],

0 commit comments

Comments
 (0)