From bfab1d0ccb5df7cb6c7b3e957cdf123947f12b29 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 27 Oct 2025 13:29:12 +0800 Subject: [PATCH] fix: resolve TypeScript type errors in test files - Add vitest/globals to tsconfig.json types array to provide type definitions for global test functions (describe, it, expect, vi) - Fix vi.fn type parameter in useDirectorySettings.test.tsx from <[], Promise> to <() => Promise> - Remove unused setMcpConfig import from MSW handlers - Add type assertions for mock.calls access in McpFormModal tests to resolve union type inference issues This ensures pnpm typecheck passes without errors while maintaining test functionality with vitest globals: true configuration. --- tests/components/McpFormModal.test.tsx | 6 +++--- tests/hooks/useDirectorySettings.test.tsx | 2 +- tests/msw/handlers.ts | 1 - tsconfig.json | 3 ++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/components/McpFormModal.test.tsx b/tests/components/McpFormModal.test.tsx index f5d5595..6f72ff7 100644 --- a/tests/components/McpFormModal.test.tsx +++ b/tests/components/McpFormModal.test.tsx @@ -203,7 +203,7 @@ const renderForm = (props?: Partial>) fireEvent.click(screen.getByText("common.add")); await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1)); - const [id, payload, options] = onSave.mock.calls[0]; + const [id, payload, options] = (onSave as any).mock.calls[0]; expect(id).toBe("my-server"); expect(payload).toMatchObject({ id: "my-server", @@ -281,7 +281,7 @@ command = "run" fireEvent.click(screen.getByText("common.add")); await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1)); - const [id, payload] = onSave.mock.calls[0]; + const [id, payload] = (onSave as any).mock.calls[0]; expect(id).toBe("demo"); expect(payload.server).toEqual({ type: "stdio", command: "run" }); expect(toastErrorMock).not.toHaveBeenCalled(); @@ -342,7 +342,7 @@ type = "stdio" fireEvent.click(screen.getByText("common.save")); await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1)); - const [id, entry, options] = onSave.mock.calls[0]; + const [id, entry, options] = (onSave as any).mock.calls[0]; expect(id).toBe("existing"); expect(entry.server.command).toBe("updated"); expect(entry.enabled).toBe(true); diff --git a/tests/hooks/useDirectorySettings.test.tsx b/tests/hooks/useDirectorySettings.test.tsx index dbbcaa4..2099c40 100644 --- a/tests/hooks/useDirectorySettings.test.tsx +++ b/tests/hooks/useDirectorySettings.test.tsx @@ -7,7 +7,7 @@ const getAppConfigDirOverrideMock = vi.hoisted(() => vi.fn()); const getConfigDirMock = vi.hoisted(() => vi.fn()); const selectConfigDirectoryMock = vi.hoisted(() => vi.fn()); const setAppConfigDirOverrideMock = vi.hoisted(() => vi.fn()); -const homeDirMock = vi.hoisted(() => vi.fn<[], Promise>()); +const homeDirMock = vi.hoisted(() => vi.fn<() => Promise>()); const joinMock = vi.hoisted(() => vi.fn(async (...segments: string[]) => segments.join("/"))); const toastErrorMock = vi.hoisted(() => vi.fn()); diff --git a/tests/msw/handlers.ts b/tests/msw/handlers.ts index ff5aa07..320f3ca 100644 --- a/tests/msw/handlers.ts +++ b/tests/msw/handlers.ts @@ -16,7 +16,6 @@ import { getAppConfigDirOverride, setAppConfigDirOverrideState, getMcpConfig, - setMcpConfig, setMcpServerEnabled, upsertMcpServer, deleteMcpServer, diff --git a/tsconfig.json b/tsconfig.json index 47c0d44..54e2a0b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,8 @@ "baseUrl": ".", "paths": { "@/*": ["src/*"] - } + }, + "types": ["vitest/globals"] }, "include": ["src/**/*", "tests/**/*"], "references": [{ "path": "./tsconfig.node.json" }]