refactor: remove any types from test files (batch 5)

Remove explicit any types from 14 test files:
- useMissingNodes.test.ts (1 instance)
- DescriptionTabPanel.test.ts (1 instance)
- PackEnableToggle.test.ts (3 instances)
- NodeConflictDialogContent.test.ts (7 instances)
- queueStore.test.ts (2 instances)
- useIntWidget.test.ts (1 instance)
- useFloatWidget.test.ts (1 instance)
- FormSelectButton.test.ts (3 instances)
- useTemplateWorkflows.test.ts (1 instance)
- useFrontendVersionMismatchWarning.test.ts (1 instance)
- releaseService.test.ts (1 instance)
- useSubscription.test.ts (1 instance)
- assetService.test.ts (1 instance)
- ResultGallery.test.ts (2 instances)

Used typed mock objects, ReturnType pattern, and specific type aliases
where appropriate. All changes pass typecheck with 0 errors.
This commit is contained in:
Johnpaul
2026-01-22 03:30:18 +01:00
parent dbf6d02f0d
commit 2aa4885696
14 changed files with 116 additions and 36 deletions

View File

@@ -117,7 +117,7 @@ describe('ResultGallery', () => {
const wrapper = mountGallery({ activeIndex: -1 })
// Initially galleryVisible should be false
const vm: any = wrapper.vm
const vm = wrapper.vm as unknown as { galleryVisible: boolean }
expect(vm.galleryVisible).toBe(false)
// Change activeIndex
@@ -167,7 +167,10 @@ describe('ResultGallery', () => {
expect(galleria.exists()).toBe(true)
// Check that our PT props for positioning work correctly
const pt = galleria.props('pt') as any
const pt = galleria.props('pt') as unknown as {
prevButton?: { style?: string }
nextButton?: { style?: string }
}
expect(pt?.prevButton?.style).toContain('position: fixed')
expect(pt?.nextButton?.style).toContain('position: fixed')
})

View File

@@ -67,7 +67,7 @@ const MOCK_ASSETS = {
} as const
// Helper functions
function mockApiResponse(assets: any[], options = {}) {
function mockApiResponse(assets: unknown[], options = {}) {
const response = {
assets,
total: assets.length,

View File

@@ -38,7 +38,7 @@ vi.mock('@/composables/useErrorHandling', () => ({
useErrorHandling: vi.fn(() => ({
wrapWithErrorHandlingAsync: vi.fn(
(fn, errorHandler) =>
async (...args: any[]) => {
async (...args: unknown[]) => {
try {
return await fn(...args)
} catch (error) {

View File

@@ -190,7 +190,7 @@ describe('useReleaseService', () => {
})
it('should set loading state correctly', async () => {
let resolvePromise: (value: any) => void
let resolvePromise: (value: unknown) => void
const promise = new Promise((resolve) => {
resolvePromise = resolve
})

View File

@@ -40,17 +40,20 @@ vi.mock('@/scripts/api', () => ({
// Mock vue-i18n
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string, params?: any) => {
t: (key: string, params?: Record<string, string | number> | unknown) => {
if (key === 'g.versionMismatchWarning')
return 'Version Compatibility Warning'
if (key === 'g.versionMismatchWarningMessage' && params) {
return `${params.warning}: ${params.detail} Visit https://docs.comfy.org/installation/update_comfyui#common-update-issues for update instructions.`
const p = params as Record<string, string>
return `${p.warning}: ${p.detail} Visit https://docs.comfy.org/installation/update_comfyui#common-update-issues for update instructions.`
}
if (key === 'g.frontendOutdated' && params) {
return `Frontend version ${params.frontendVersion} is outdated. Backend requires ${params.requiredVersion} or higher.`
const p = params as Record<string, string>
return `Frontend version ${p.frontendVersion} is outdated. Backend requires ${p.requiredVersion} or higher.`
}
if (key === 'g.frontendNewer' && params) {
return `Frontend version ${params.frontendVersion} may not be compatible with backend version ${params.backendVersion}.`
const p = params as Record<string, string>
return `Frontend version ${p.frontendVersion} may not be compatible with backend version ${p.backendVersion}.`
}
return key
}

View File

@@ -49,8 +49,10 @@ vi.mock('@/stores/dialogStore', () => ({
// Mock fetch
global.fetch = vi.fn()
type MockWorkflowTemplatesStore = ReturnType<typeof useWorkflowTemplatesStore>
describe('useTemplateWorkflows', () => {
let mockWorkflowTemplatesStore: any
let mockWorkflowTemplatesStore: MockWorkflowTemplatesStore
beforeEach(() => {
mockWorkflowTemplatesStore = {
@@ -70,7 +72,8 @@ describe('useTemplateWorkflows', () => {
mediaType: 'image',
mediaSubtype: 'jpg',
sourceModule: 'default',
localizedTitle: 'Template 1'
localizedTitle: 'Template 1',
description: 'Template 1 description'
},
{
name: 'template2',
@@ -91,14 +94,15 @@ describe('useTemplateWorkflows', () => {
mediaType: 'image',
mediaSubtype: 'jpg',
localizedTitle: 'Template 1',
localizedDescription: 'A default template'
localizedDescription: 'A default template',
description: 'Template 1 description'
}
]
}
]
}
]
}
} as unknown as MockWorkflowTemplatesStore
vi.mocked(useWorkflowTemplatesStore).mockReturnValue(
mockWorkflowTemplatesStore

View File

@@ -8,7 +8,7 @@ describe('FormSelectButton Core Component', () => {
// Type-safe helper for mounting component
const mountComponent = (
modelValue: string | null | undefined = null,
options: (string | number | Record<string, any>)[] = [],
options: unknown[] = [],
props: Record<string, unknown> = {}
) => {
return mount(FormSelectButton, {
@@ -17,7 +17,11 @@ describe('FormSelectButton Core Component', () => {
},
props: {
modelValue,
options: options as any,
options: options as (
| string
| number
| { label: string; value: string | number }
)[],
...props
}
})
@@ -474,7 +478,7 @@ describe('FormSelectButton Core Component', () => {
})
it('handles mixed type options safely', () => {
const mixedOptions: any[] = [
const mixedOptions: unknown[] = [
'string',
123,
{ label: 'Object', value: 'obj' }

View File

@@ -14,13 +14,28 @@ vi.mock('@/platform/settings/settingStore', () => ({
const { onFloatValueChange } = _for_testing
type MockWidget = {
type: 'number'
name: string
y: number
options: {
round?: number
min?: number
max?: number
}
value: number
}
describe('useFloatWidget', () => {
describe('onFloatValueChange', () => {
let widget: any
let widget: MockWidget
beforeEach(() => {
// Reset the widget before each test
widget = {
type: 'number',
name: 'test_widget',
y: 0,
options: {},
value: 0
}

View File

@@ -14,13 +14,27 @@ vi.mock('@/platform/settings/settingStore', () => ({
const { onValueChange } = _for_testing
type MockWidget = {
type: 'number'
name: string
y: number
options: {
step2?: number
min?: number
}
value: number
}
describe('useIntWidget', () => {
describe('onValueChange', () => {
let widget: any
let widget: MockWidget
beforeEach(() => {
// Reset the widget before each test
widget = {
type: 'number',
name: 'test_widget',
y: 0,
options: {},
value: 0
}

View File

@@ -37,7 +37,11 @@ function createHistoryJob(createTime: number, id: string): JobListItem {
const createTaskOutput = (
nodeId: string = 'node-1',
images: any[] = []
images: {
type?: 'output' | 'input' | 'temp'
filename?: string
subfolder?: string
}[] = []
): TaskOutput => ({
[nodeId]: {
images

View File

@@ -7,6 +7,14 @@ import { computed, ref } from 'vue'
import NodeConflictDialogContent from '@/workbench/extensions/manager/components/manager/NodeConflictDialogContent.vue'
import type { ConflictDetectionResult } from '@/workbench/extensions/manager/types/conflictDetectionTypes'
type NodeConflictDialogVM = {
importFailedExpanded: boolean
conflictsExpanded: boolean
extensionsExpanded: boolean
allConflictDetails: { type: string }[]
importFailedConflicts: string[]
}
// Mock getConflictMessage utility
vi.mock('@/utils/conflictMessageUtil', () => ({
getConflictMessage: vi.fn((conflict) => {
@@ -287,25 +295,43 @@ describe('NodeConflictDialogContent', () => {
await importFailedHeader.trigger('click')
// Verify import failed panel is open
expect((wrapper.vm as any).importFailedExpanded).toBe(true)
expect((wrapper.vm as any).conflictsExpanded).toBe(false)
expect((wrapper.vm as any).extensionsExpanded).toBe(false)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).importFailedExpanded
).toBe(true)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).conflictsExpanded
).toBe(false)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).extensionsExpanded
).toBe(false)
// Open conflicts panel
await conflictsHeader.trigger('click')
// Verify conflicts panel is open and others are closed
expect((wrapper.vm as any).importFailedExpanded).toBe(false)
expect((wrapper.vm as any).conflictsExpanded).toBe(true)
expect((wrapper.vm as any).extensionsExpanded).toBe(false)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).importFailedExpanded
).toBe(false)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).conflictsExpanded
).toBe(true)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).extensionsExpanded
).toBe(false)
// Open extensions panel
await extensionsHeader.trigger('click')
// Verify extensions panel is open and others are closed
expect((wrapper.vm as any).importFailedExpanded).toBe(false)
expect((wrapper.vm as any).conflictsExpanded).toBe(false)
expect((wrapper.vm as any).extensionsExpanded).toBe(true)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).importFailedExpanded
).toBe(false)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).conflictsExpanded
).toBe(false)
expect(
(wrapper.vm as unknown as NodeConflictDialogVM).extensionsExpanded
).toBe(true)
})
})
@@ -450,10 +476,12 @@ describe('NodeConflictDialogContent', () => {
const wrapper = createWrapper()
// Verify that import_failed conflicts are filtered out from main conflicts
const vm = wrapper.vm as any
const vm = wrapper.vm as unknown as NodeConflictDialogVM
expect(vm.allConflictDetails).toHaveLength(3) // Should not include import_failed
expect(
vm.allConflictDetails.every((c: any) => c.type !== 'import_failed')
vm.allConflictDetails.every(
(c: { type: string }) => c.type !== 'import_failed'
)
).toBe(true)
})
@@ -462,7 +490,7 @@ describe('NodeConflictDialogContent', () => {
const wrapper = createWrapper()
// Verify that only import_failed packages are extracted
const vm = wrapper.vm as any
const vm = wrapper.vm as unknown as NodeConflictDialogVM
expect(vm.importFailedConflicts).toHaveLength(1)
expect(vm.importFailedConflicts[0]).toBe('Test Package 3')
})

View File

@@ -17,7 +17,7 @@ vi.mock('es-toolkit/compat', async () => {
const actual = await vi.importActual('es-toolkit/compat')
return {
...actual,
debounce: <T extends (...args: any[]) => any>(fn: T) => fn
debounce: <T extends (...args: unknown[]) => unknown>(fn: T) => fn
}
})
@@ -61,7 +61,10 @@ describe('PackEnableToggle', () => {
const mountComponent = ({
props = {},
installedPacks = {}
}: Record<string, any> = {}): VueWrapper => {
}: {
props?: Record<string, unknown>
installedPacks?: unknown
} = {}): VueWrapper => {
const i18n = createI18n({
legacy: false,
locale: 'en',
@@ -73,7 +76,7 @@ describe('PackEnableToggle', () => {
enablePack: mockEnablePack,
disablePack: mockDisablePack,
installedPacks
} as any)
} as unknown as ReturnType<typeof useComfyManagerStore>)
return mount(PackEnableToggle, {
props: {

View File

@@ -41,7 +41,7 @@ describe('DescriptionTabPanel', () => {
const sections = wrapper
.findComponent({ name: 'InfoTextSection' })
.props('sections')
return sections.find((s: any) => s.title === title)
return sections.find((s: { title: string }) => s.title === title)
}
const createNodePack = (

View File

@@ -12,7 +12,9 @@ vi.mock('@vueuse/core', async () => {
const actual = await vi.importActual('@vueuse/core')
return {
...actual,
createSharedComposable: <Fn extends (...args: any[]) => any>(fn: Fn) => fn
createSharedComposable: <Fn extends (...args: unknown[]) => unknown>(
fn: Fn
) => fn
}
})