From fd8118564aac47a35c808c9e361972d0d97afc71 Mon Sep 17 00:00:00 2001 From: Johnpaul Date: Thu, 22 Jan 2026 19:32:16 +0100 Subject: [PATCH] refactor: remove 'as any' assertions from test files (batch 1: 16 files) - Fixed 15 as any type assertions across 16 test files - Used proper TypeScript types: unknown, Settings, ComfyWorkflowJSON, etc. - Added missing type imports where needed - Replaced as any with proper type intersections for Vue component testing Files modified: - ComboWidget.test.ts: Use explicit Values union type - settingStore.test.ts: Import and use Settings type - WhatsNewPopup.test.ts: Type assertion with component interface - useMinimap.test.ts: Remove unnecessary cast (renderMinimap is public) - LGraphNode.test.ts: Remove unnecessary any cast from undefined - WidgetGalleria.test.ts: Type intersection for vm access - WidgetInputNumberInput.test.ts: Use unknown to number cast - jobOutputCache.test.ts: Import ComfyWorkflowJSON type - mediaCacheService.test.ts: Use Partial cast - registrySearchProvider.test.ts: Use ReturnType - firebaseAuthStore.test.ts: Cast to UserCredential - queueStore.test.ts: Use Record for delete - usePacksSelection.test.ts: Cast undefined to unknown to string - usePacksStatus.test.ts: Cast undefined to unknown to string - useConflictDetection.test.ts: Use inline type for ImportFailInfo Reduced as any count from 326 to 311 instances. --- src/lib/litegraph/src/widgets/ComboWidget.test.ts | 7 ++++++- src/platform/settings/settingStore.test.ts | 3 ++- src/platform/updates/components/WhatsNewPopup.test.ts | 4 +++- .../extensions/minimap/composables/useMinimap.test.ts | 5 +---- .../extensions/vueNodes/components/LGraphNode.test.ts | 2 +- .../vueNodes/widgets/components/WidgetGalleria.test.ts | 2 +- .../widgets/components/WidgetInputNumberInput.test.ts | 2 +- src/services/jobOutputCache.test.ts | 5 ++++- src/services/mediaCacheService.test.ts | 2 +- src/services/providers/registrySearchProvider.test.ts | 2 +- src/stores/firebaseAuthStore.test.ts | 2 +- src/stores/queueStore.test.ts | 2 +- .../manager/composables/nodePack/usePacksSelection.test.ts | 2 +- .../manager/composables/nodePack/usePacksStatus.test.ts | 2 +- .../manager/composables/useConflictDetection.test.ts | 2 +- 15 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/lib/litegraph/src/widgets/ComboWidget.test.ts b/src/lib/litegraph/src/widgets/ComboWidget.test.ts index f080dbab7..5a41d45df 100644 --- a/src/lib/litegraph/src/widgets/ComboWidget.test.ts +++ b/src/lib/litegraph/src/widgets/ComboWidget.test.ts @@ -1051,7 +1051,12 @@ describe('ComboWidget', () => { createMockWidgetConfig({ name: 'mode', value: 'test', - options: { values: null as any } + options: { + values: null as unknown as + | string[] + | Record + | (() => string[]) + } }), node ) diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index 60d7acd1c..43b79d2fd 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -6,6 +6,7 @@ import { useSettingStore } from '@/platform/settings/settingStore' import type { SettingParams } from '@/platform/settings/types' +import type { Settings } from '@/schemas/apiSchema' import { api } from '@/scripts/api' import { app } from '@/scripts/app' @@ -45,7 +46,7 @@ describe('useSettingStore', () => { describe('loadSettingValues', () => { it('should load settings from API', async () => { const mockSettings = { 'test.setting': 'value' } - vi.mocked(api.getSettings).mockResolvedValue(mockSettings as any) + vi.mocked(api.getSettings).mockResolvedValue(mockSettings as Settings) await store.loadSettingValues() diff --git a/src/platform/updates/components/WhatsNewPopup.test.ts b/src/platform/updates/components/WhatsNewPopup.test.ts index f40399730..41a0008eb 100644 --- a/src/platform/updates/components/WhatsNewPopup.test.ts +++ b/src/platform/updates/components/WhatsNewPopup.test.ts @@ -165,7 +165,9 @@ describe('WhatsNewPopup', () => { wrapper = mountComponent() // Call the close method directly instead of triggering DOM event - await (wrapper.vm as any).closePopup() + await ( + wrapper.vm as typeof wrapper.vm & { closePopup: () => Promise } + ).closePopup() expect(wrapper.emitted('whats-new-dismissed')).toBeTruthy() }) diff --git a/src/renderer/extensions/minimap/composables/useMinimap.test.ts b/src/renderer/extensions/minimap/composables/useMinimap.test.ts index 22458744c..39c253ad6 100644 --- a/src/renderer/extensions/minimap/composables/useMinimap.test.ts +++ b/src/renderer/extensions/minimap/composables/useMinimap.test.ts @@ -976,10 +976,7 @@ describe('useMinimap', () => { await minimap.init() - const renderMinimap = (minimap as any).renderMinimap - if (renderMinimap) { - renderMinimap() - } + minimap.renderMinimap() expect(mockContext2D.fillRect).toHaveBeenCalled() expect(mockContext2D.fillStyle).toBeDefined() diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts index b93b360fe..5b61a50e7 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts @@ -76,7 +76,7 @@ vi.mock( executing: computed(() => mockData.mockExecuting), progress: computed(() => undefined), progressPercentage: computed(() => undefined), - progressState: computed(() => undefined as any), + progressState: computed(() => undefined), executionState: computed(() => 'idle' as const) })) }) diff --git a/src/renderer/extensions/vueNodes/widgets/components/WidgetGalleria.test.ts b/src/renderer/extensions/vueNodes/widgets/components/WidgetGalleria.test.ts index 399edb514..8937d8c50 100644 --- a/src/renderer/extensions/vueNodes/widgets/components/WidgetGalleria.test.ts +++ b/src/renderer/extensions/vueNodes/widgets/components/WidgetGalleria.test.ts @@ -290,7 +290,7 @@ describe('WidgetGalleria Image Display', () => { await galleria.vm.$emit('update:activeIndex', 2) // Check that the internal activeIndex ref was updated - const vm = wrapper.vm as any + const vm = wrapper.vm as typeof wrapper.vm & { activeIndex: number } expect(vm.activeIndex).toBe(2) }) }) diff --git a/src/renderer/extensions/vueNodes/widgets/components/WidgetInputNumberInput.test.ts b/src/renderer/extensions/vueNodes/widgets/components/WidgetInputNumberInput.test.ts index 7eb3890bc..1d1b6ee0c 100644 --- a/src/renderer/extensions/vueNodes/widgets/components/WidgetInputNumberInput.test.ts +++ b/src/renderer/extensions/vueNodes/widgets/components/WidgetInputNumberInput.test.ts @@ -202,7 +202,7 @@ describe('WidgetInputNumberInput Edge Cases for Precision Handling', () => { global: { plugins: [i18n] }, props: { widget, - modelValue: undefined as any + modelValue: undefined as unknown as number } }) diff --git a/src/services/jobOutputCache.test.ts b/src/services/jobOutputCache.test.ts index 38e47e973..52225ec0a 100644 --- a/src/services/jobOutputCache.test.ts +++ b/src/services/jobOutputCache.test.ts @@ -4,6 +4,7 @@ import type { JobDetail, JobListItem } from '@/platform/remote/comfyui/jobs/jobTypes' +import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema' import { ResultItemImpl, TaskItemImpl } from '@/stores/queueStore' vi.mock('@/platform/remote/comfyui/jobs/fetchJobs', () => ({ @@ -254,7 +255,9 @@ describe('jobOutputCache', () => { const mockWorkflow = { version: 1 } vi.mocked(fetchJobDetail).mockResolvedValue(mockDetail) - vi.mocked(extractWorkflow).mockResolvedValue(mockWorkflow as any) + vi.mocked(extractWorkflow).mockResolvedValue( + mockWorkflow as ComfyWorkflowJSON + ) const result = await getJobWorkflow('job-wf') diff --git a/src/services/mediaCacheService.test.ts b/src/services/mediaCacheService.test.ts index 1860344cc..1ecc0658f 100644 --- a/src/services/mediaCacheService.test.ts +++ b/src/services/mediaCacheService.test.ts @@ -7,7 +7,7 @@ global.fetch = vi.fn() global.URL = { createObjectURL: vi.fn(() => 'blob:mock-url'), revokeObjectURL: vi.fn() -} as any +} as Partial as typeof URL describe('mediaCacheService', () => { describe('URL reference counting', () => { diff --git a/src/services/providers/registrySearchProvider.test.ts b/src/services/providers/registrySearchProvider.test.ts index b564bf7a7..28f5cee0d 100644 --- a/src/services/providers/registrySearchProvider.test.ts +++ b/src/services/providers/registrySearchProvider.test.ts @@ -27,7 +27,7 @@ describe('useComfyRegistrySearchProvider', () => { call: mockListAllPacksCall, clear: mockListAllPacksClear } - } as any) + } as unknown as ReturnType) }) describe('searchPacks', () => { diff --git a/src/stores/firebaseAuthStore.test.ts b/src/stores/firebaseAuthStore.test.ts index 6bdc9ad98..88d757149 100644 --- a/src/stores/firebaseAuthStore.test.ts +++ b/src/stores/firebaseAuthStore.test.ts @@ -238,7 +238,7 @@ describe('useFirebaseAuthStore', () => { // Now, succeed on next attempt vi.mocked(firebaseAuth.signInWithEmailAndPassword).mockResolvedValueOnce({ user: mockUser - } as any) + } as unknown as UserCredential) await store.login('test@example.com', 'correct-password') }) diff --git a/src/stores/queueStore.test.ts b/src/stores/queueStore.test.ts index 8f3289808..fa5b4780e 100644 --- a/src/stores/queueStore.test.ts +++ b/src/stores/queueStore.test.ts @@ -493,7 +493,7 @@ describe('useQueueStore', () => { it('should recreate TaskItemImpl when outputs_count changes', async () => { // Initial load without outputs_count const jobWithoutOutputsCount = createHistoryJob(10, 'job-1') - delete (jobWithoutOutputsCount as any).outputs_count + delete (jobWithoutOutputsCount as Record).outputs_count mockGetQueue.mockResolvedValue({ Running: [], Pending: [] }) mockGetHistory.mockResolvedValue([jobWithoutOutputsCount]) diff --git a/src/workbench/extensions/manager/composables/nodePack/usePacksSelection.test.ts b/src/workbench/extensions/manager/composables/nodePack/usePacksSelection.test.ts index c38fc9c33..132d0a928 100644 --- a/src/workbench/extensions/manager/composables/nodePack/usePacksSelection.test.ts +++ b/src/workbench/extensions/manager/composables/nodePack/usePacksSelection.test.ts @@ -323,7 +323,7 @@ describe('usePacksSelection', () => { describe('edge cases', () => { it('should handle packs with undefined ids', () => { const nodePacks = ref([ - { ...createMockPack('pack1'), id: undefined as any }, + { ...createMockPack('pack1'), id: undefined as unknown as string }, createMockPack('pack2') ]) diff --git a/src/workbench/extensions/manager/composables/nodePack/usePacksStatus.test.ts b/src/workbench/extensions/manager/composables/nodePack/usePacksStatus.test.ts index 2fbabb3fb..c2c30e899 100644 --- a/src/workbench/extensions/manager/composables/nodePack/usePacksStatus.test.ts +++ b/src/workbench/extensions/manager/composables/nodePack/usePacksStatus.test.ts @@ -107,7 +107,7 @@ describe('usePacksStatus', () => { it('should handle packs without ids', () => { const nodePacks = ref([ - { ...createMockPack('pack1'), id: undefined as any }, + { ...createMockPack('pack1'), id: undefined as unknown as string }, createMockPack('pack2') ]) diff --git a/src/workbench/extensions/manager/composables/useConflictDetection.test.ts b/src/workbench/extensions/manager/composables/useConflictDetection.test.ts index 28fa8302c..5592a5892 100644 --- a/src/workbench/extensions/manager/composables/useConflictDetection.test.ts +++ b/src/workbench/extensions/manager/composables/useConflictDetection.test.ts @@ -413,7 +413,7 @@ describe('useConflictDetection', () => { error: 'Import error', name: 'fail-pack', path: '/path/to/pack' - } as any // The actual API returns different structure than types + } as { error?: string; traceback?: string } | null // The actual API returns different structure than types }) // Mock registry response for the package