mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-19 22:34:15 +00:00
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<typeof URL> cast - registrySearchProvider.test.ts: Use ReturnType<typeof store> - firebaseAuthStore.test.ts: Cast to UserCredential - queueStore.test.ts: Use Record<string, unknown> 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.
This commit is contained in:
@@ -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, string>
|
||||
| (() => string[])
|
||||
}
|
||||
}),
|
||||
node
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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<void> }
|
||||
).closePopup()
|
||||
|
||||
expect(wrapper.emitted('whats-new-dismissed')).toBeTruthy()
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}))
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ global.fetch = vi.fn()
|
||||
global.URL = {
|
||||
createObjectURL: vi.fn(() => 'blob:mock-url'),
|
||||
revokeObjectURL: vi.fn()
|
||||
} as any
|
||||
} as Partial<typeof URL> as typeof URL
|
||||
|
||||
describe('mediaCacheService', () => {
|
||||
describe('URL reference counting', () => {
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('useComfyRegistrySearchProvider', () => {
|
||||
call: mockListAllPacksCall,
|
||||
clear: mockListAllPacksClear
|
||||
}
|
||||
} as any)
|
||||
} as unknown as ReturnType<typeof useComfyRegistryStore>)
|
||||
})
|
||||
|
||||
describe('searchPacks', () => {
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
@@ -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<string, unknown>).outputs_count
|
||||
|
||||
mockGetQueue.mockResolvedValue({ Running: [], Pending: [] })
|
||||
mockGetHistory.mockResolvedValue([jobWithoutOutputsCount])
|
||||
|
||||
@@ -323,7 +323,7 @@ describe('usePacksSelection', () => {
|
||||
describe('edge cases', () => {
|
||||
it('should handle packs with undefined ids', () => {
|
||||
const nodePacks = ref<NodePack[]>([
|
||||
{ ...createMockPack('pack1'), id: undefined as any },
|
||||
{ ...createMockPack('pack1'), id: undefined as unknown as string },
|
||||
createMockPack('pack2')
|
||||
])
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ describe('usePacksStatus', () => {
|
||||
|
||||
it('should handle packs without ids', () => {
|
||||
const nodePacks = ref<NodePack[]>([
|
||||
{ ...createMockPack('pack1'), id: undefined as any },
|
||||
{ ...createMockPack('pack1'), id: undefined as unknown as string },
|
||||
createMockPack('pack2')
|
||||
])
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user