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

Remove explicit any types from 3 test files:
- SubgraphMemory.test.ts (10 instances)
- minimapCanvasRenderer.test.ts (8 instances)
- useImageLoader.test.ts (8 instances)

Changes:
- Created InputWithWidget type for test-specific widget properties
- Used `unknown` type with proper type annotations for mock store properties
- Used `as unknown as T` pattern for mock objects
- Used `ReturnType<typeof func>` for store mock return types

All changes pass typecheck and tests.
This commit is contained in:
Johnpaul
2026-01-22 00:08:42 +01:00
parent 27359f945b
commit 94fc1f6e30
3 changed files with 63 additions and 39 deletions

View File

@@ -7,17 +7,26 @@ const mockCanvasManager = {
updateMaskColor: vi.fn().mockResolvedValue(undefined)
}
const mockStore = {
imgCanvas: null as any,
maskCanvas: null as any,
rgbCanvas: null as any,
imgCtx: null as any,
maskCtx: null as any,
image: null as any
const mockStore: {
imgCanvas: unknown
maskCanvas: unknown
rgbCanvas: unknown
imgCtx: unknown
maskCtx: unknown
image: unknown
} = {
imgCanvas: null,
maskCanvas: null,
rgbCanvas: null,
imgCtx: null,
maskCtx: null,
image: null
}
const mockDataStore = {
inputData: null as any
const mockDataStore: {
inputData: unknown
} = {
inputData: null
}
vi.mock('@/stores/maskEditorStore', () => ({
@@ -33,7 +42,8 @@ vi.mock('@/composables/maskeditor/useCanvasManager', () => ({
}))
vi.mock('@vueuse/core', () => ({
createSharedComposable: (fn: any) => fn
createSharedComposable: <T extends (...args: unknown[]) => unknown>(fn: T) =>
fn
}))
describe('useImageLoader', () => {
@@ -104,10 +114,10 @@ describe('useImageLoader', () => {
await loader.loadImages()
expect(mockStore.maskCanvas.width).toBe(512)
expect(mockStore.maskCanvas.height).toBe(512)
expect(mockStore.rgbCanvas.width).toBe(512)
expect(mockStore.rgbCanvas.height).toBe(512)
expect((mockStore.maskCanvas as { width: number }).width).toBe(512)
expect((mockStore.maskCanvas as { height: number }).height).toBe(512)
expect((mockStore.rgbCanvas as { width: number }).width).toBe(512)
expect((mockStore.rgbCanvas as { height: number }).height).toBe(512)
})
it('should clear canvas contexts', async () => {
@@ -115,8 +125,12 @@ describe('useImageLoader', () => {
await loader.loadImages()
expect(mockStore.imgCtx.clearRect).toHaveBeenCalledWith(0, 0, 0, 0)
expect(mockStore.maskCtx.clearRect).toHaveBeenCalledWith(0, 0, 0, 0)
expect(
(mockStore.imgCtx as { clearRect: ReturnType<typeof vi.fn> }).clearRect
).toHaveBeenCalledWith(0, 0, 0, 0)
expect(
(mockStore.maskCtx as { clearRect: ReturnType<typeof vi.fn> }).clearRect
).toHaveBeenCalledWith(0, 0, 0, 0)
})
it('should call canvasManager methods', async () => {
@@ -188,10 +202,10 @@ describe('useImageLoader', () => {
await loader.loadImages()
expect(mockStore.maskCanvas.width).toBe(1024)
expect(mockStore.maskCanvas.height).toBe(768)
expect(mockStore.rgbCanvas.width).toBe(1024)
expect(mockStore.rgbCanvas.height).toBe(768)
expect((mockStore.maskCanvas as { width: number }).width).toBe(1024)
expect((mockStore.maskCanvas as { height: number }).height).toBe(768)
expect((mockStore.rgbCanvas as { width: number }).width).toBe(1024)
expect((mockStore.rgbCanvas as { height: number }).height).toBe(768)
})
})
})

View File

@@ -10,6 +10,12 @@ import {
createTestSubgraphNode
} from './__fixtures__/subgraphHelpers'
type InputWithWidget = {
_widget?: IWidget | { type: string; value: unknown; name: string }
_connection?: { id: number; type: string }
_listenerController?: AbortController
}
describe.skip('SubgraphNode Memory Management', () => {
describe.skip('Event Listener Cleanup', () => {
it('should register event listeners on construction', () => {
@@ -308,14 +314,14 @@ describe.skip('SubgraphMemory - Widget Reference Management', () => {
// Set widget reference
if (input && '_widget' in input) {
;(input as any)._widget = mockWidget
expect((input as any)._widget).toBe(mockWidget)
;(input as InputWithWidget)._widget = mockWidget
expect((input as InputWithWidget)._widget).toBe(mockWidget)
}
// Clear widget reference
if (input && '_widget' in input) {
;(input as any)._widget = undefined
expect((input as any)._widget).toBeUndefined()
;(input as InputWithWidget)._widget = undefined
expect((input as InputWithWidget)._widget).toBeUndefined()
}
}
)
@@ -360,30 +366,34 @@ describe.skip('SubgraphMemory - Widget Reference Management', () => {
// Set up references that should be cleaned up
const mockReferences = {
widget: { type: 'number', value: 42 },
widget: { type: 'number', value: 42, name: 'mock_widget' },
connection: { id: 1, type: 'number' },
listener: vi.fn()
}
// Set references
if (input) {
;(input as any)._widget = mockReferences.widget
;(input as any)._connection = mockReferences.connection
;(input as InputWithWidget)._widget = mockReferences.widget
;(input as InputWithWidget)._connection = mockReferences.connection
}
if (output) {
;(input as any)._connection = mockReferences.connection
;(input as InputWithWidget)._connection = mockReferences.connection
}
// Verify references are set
expect((input as any)?._widget).toBe(mockReferences.widget)
expect((input as any)?._connection).toBe(mockReferences.connection)
expect((input as InputWithWidget)?._widget).toBe(mockReferences.widget)
expect((input as InputWithWidget)?._connection).toBe(
mockReferences.connection
)
// Simulate proper cleanup (what onRemoved should do)
subgraphNode.onRemoved()
// Input-specific listeners should be cleaned up (this works)
if (input && '_listenerController' in input) {
expect((input as any)._listenerController?.signal.aborted).toBe(true)
expect(
(input as InputWithWidget)._listenerController?.signal.aborted
).toBe(true)
}
}
)

View File

@@ -33,11 +33,11 @@ describe('minimapCanvasRenderer', () => {
fillStyle: '',
strokeStyle: '',
lineWidth: 1
} as any
} as unknown as CanvasRenderingContext2D
mockCanvas = {
getContext: vi.fn().mockReturnValue(mockContext)
} as any
} as unknown as HTMLCanvasElement
mockGraph = {
_nodes: [
@@ -63,11 +63,11 @@ describe('minimapCanvasRenderer', () => {
_groups: [],
links: {},
getNodeById: vi.fn()
} as any
} as unknown as LGraph
vi.mocked(useColorPaletteStore).mockReturnValue({
completedActivePalette: { light_theme: false }
} as any)
} as unknown as ReturnType<typeof useColorPaletteStore>)
})
it('should clear canvas and render nodes', () => {
@@ -203,7 +203,7 @@ describe('minimapCanvasRenderer', () => {
size: [400, 300],
color: '#0000FF'
}
] as any
] as unknown as typeof mockGraph._groups
const context: MinimapRenderContext = {
bounds: { minX: 0, minY: 0, width: 500, height: 400 },
@@ -236,14 +236,14 @@ describe('minimapCanvasRenderer', () => {
{
links: [1]
}
] as any
] as unknown as (typeof mockGraph._nodes)[0]['outputs']
// Create a hybrid Map/Object for links as LiteGraph expects
const linksMap = new Map([[1, { id: 1, target_id: 2 }]])
const links = Object.assign(linksMap, {
1: { id: 1, target_id: 2 }
})
mockGraph.links = links as any
mockGraph.links = links as unknown as typeof mockGraph.links
mockGraph.getNodeById = vi.fn().mockReturnValue(targetNode)
@@ -277,7 +277,7 @@ describe('minimapCanvasRenderer', () => {
it('should handle light theme colors', () => {
vi.mocked(useColorPaletteStore).mockReturnValue({
completedActivePalette: { light_theme: true }
} as any)
} as unknown as ReturnType<typeof useColorPaletteStore>)
const context: MinimapRenderContext = {
bounds: { minX: 0, minY: 0, width: 500, height: 400 },