refactor: remove as any from 4 test files (batch 13)

Fixed 20 instances across:
- useWatchWidget.test.ts (5): Remove callback casts, call with proper args
- BypassButton.test.ts (5): Cast mock nodes as unknown as LGraphNode
- LinkConnector.test.ts (5): Use CanvasPointerEvent instead of Event, type render links properly
- executableGroupNodeChildDTO.test.ts (5): Cast to unknown as LGraphNode, use vi.mocked()

Key patterns:
- Widget callbacks now called with value argument
- Partial mock objects use as unknown as TargetType
- vi.mocked() wrapper for accessing mock methods after type casting
This commit is contained in:
Johnpaul
2026-01-22 22:16:29 +01:00
parent 87c01c9819
commit 07a89ed0cb
4 changed files with 56 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createI18n } from 'vue-i18n'
import BypassButton from '@/components/graph/selectionToolbox/BypassButton.vue'
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { LGraphEventMode } from '@/lib/litegraph/src/litegraph'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { useCommandStore } from '@/stores/commandStore'
@@ -59,21 +60,21 @@ describe('BypassButton', () => {
}
it('should render bypass button', () => {
canvasStore.selectedItems = [mockLGraphNode] as any
canvasStore.selectedItems = [mockLGraphNode as unknown as LGraphNode]
const wrapper = mountComponent()
const button = wrapper.find('button')
expect(button.exists()).toBe(true)
})
it('should have correct test id', () => {
canvasStore.selectedItems = [mockLGraphNode] as any
canvasStore.selectedItems = [mockLGraphNode as unknown as LGraphNode]
const wrapper = mountComponent()
const button = wrapper.find('[data-testid="bypass-button"]')
expect(button.exists()).toBe(true)
})
it('should execute bypass command when clicked', async () => {
canvasStore.selectedItems = [mockLGraphNode] as any
canvasStore.selectedItems = [mockLGraphNode as unknown as LGraphNode]
const executeSpy = vi.spyOn(commandStore, 'execute').mockResolvedValue()
const wrapper = mountComponent()
@@ -86,7 +87,7 @@ describe('BypassButton', () => {
it('should show bypassed styling when node is bypassed', async () => {
const bypassedNode = { ...mockLGraphNode, mode: LGraphEventMode.BYPASS }
canvasStore.selectedItems = [bypassedNode] as any
canvasStore.selectedItems = [bypassedNode as unknown as LGraphNode]
vi.spyOn(commandStore, 'execute').mockResolvedValue()
const wrapper = mountComponent()
@@ -100,7 +101,10 @@ describe('BypassButton', () => {
it('should handle multiple selected items', () => {
vi.spyOn(commandStore, 'execute').mockResolvedValue()
canvasStore.selectedItems = [mockLGraphNode, mockLGraphNode] as any
canvasStore.selectedItems = [
mockLGraphNode as unknown as LGraphNode,
mockLGraphNode as unknown as LGraphNode
]
const wrapper = mountComponent()
const button = wrapper.find('button')
expect(button.exists()).toBe(true)

View File

@@ -59,9 +59,9 @@ describe('useComputedWithWidgetWatch', () => {
// Change widget value and trigger callback
const widthWidget = mockNode.widgets?.find((w) => w.name === 'width')
if (widthWidget) {
if (widthWidget && widthWidget.callback) {
widthWidget.value = 150
;(widthWidget.callback as any)?.()
widthWidget.callback(widthWidget.value)
}
await nextTick()
@@ -89,9 +89,9 @@ describe('useComputedWithWidgetWatch', () => {
// Change observed widget
const widthWidget = mockNode.widgets?.find((w) => w.name === 'width')
if (widthWidget) {
if (widthWidget && widthWidget.callback) {
widthWidget.value = 150
;(widthWidget.callback as any)?.()
widthWidget.callback(widthWidget.value)
}
await nextTick()
@@ -117,9 +117,9 @@ describe('useComputedWithWidgetWatch', () => {
// Change widget value
const widget = mockNode.widgets?.[0]
if (widget) {
if (widget && widget.callback) {
widget.value = 20
;(widget.callback as any)?.()
widget.callback(widget.value)
}
await nextTick()
@@ -139,9 +139,9 @@ describe('useComputedWithWidgetWatch', () => {
// Change widget value
const widget = mockNode.widgets?.[0]
if (widget) {
if (widget && widget.callback) {
widget.value = 20
;(widget.callback as any)?.()
widget.callback(widget.value)
}
await nextTick()
@@ -171,8 +171,8 @@ describe('useComputedWithWidgetWatch', () => {
// Trigger widget callback
const widget = mockNode.widgets?.[0]
if (widget) {
;(widget.callback as any)?.()
if (widget && widget.callback) {
widget.callback(widget.value)
}
await nextTick()

View File

@@ -1,7 +1,11 @@
// TODO: Fix these tests after migration
import { beforeEach, describe, expect, test, vi } from 'vitest'
import type { INodeInputSlot, LGraphNode } from '@/lib/litegraph/src/litegraph'
import type {
CanvasPointerEvent,
INodeInputSlot,
LGraphNode
} from '@/lib/litegraph/src/litegraph'
// We don't strictly need RenderLink interface import for the mock
import { LinkConnector } from '@/lib/litegraph/src/litegraph'
@@ -37,8 +41,11 @@ describe.skip('LinkConnector', () => {
test('should return true if at least one render link can connect', () => {
const link1 = mockRenderLinkImpl(false)
const link2 = mockRenderLinkImpl(true)
// Cast to any to satisfy the push requirement, as we only need the canConnectToInput method
connector.renderLinks.push(link1 as any, link2 as any)
type RenderLinkItem = (typeof connector.renderLinks)[number]
connector.renderLinks.push(
link1 as unknown as RenderLinkItem,
link2 as unknown as RenderLinkItem
)
expect(connector.isInputValidDrop(mockNode, mockInput)).toBe(true)
expect(link1.canConnectToInput).toHaveBeenCalledWith(mockNode, mockInput)
expect(link2.canConnectToInput).toHaveBeenCalledWith(mockNode, mockInput)
@@ -47,7 +54,11 @@ describe.skip('LinkConnector', () => {
test('should return false if no render links can connect', () => {
const link1 = mockRenderLinkImpl(false)
const link2 = mockRenderLinkImpl(false)
connector.renderLinks.push(link1 as any, link2 as any)
type RenderLinkItem = (typeof connector.renderLinks)[number]
connector.renderLinks.push(
link1 as unknown as RenderLinkItem,
link2 as unknown as RenderLinkItem
)
expect(connector.isInputValidDrop(mockNode, mockInput)).toBe(false)
expect(link1.canConnectToInput).toHaveBeenCalledWith(mockNode, mockInput)
expect(link2.canConnectToInput).toHaveBeenCalledWith(mockNode, mockInput)
@@ -57,7 +68,12 @@ describe.skip('LinkConnector', () => {
const link1 = mockRenderLinkImpl(false)
const link2 = mockRenderLinkImpl(true) // This one can connect
const link3 = mockRenderLinkImpl(false)
connector.renderLinks.push(link1 as any, link2 as any, link3 as any)
type RenderLinkItem = (typeof connector.renderLinks)[number]
connector.renderLinks.push(
link1 as unknown as RenderLinkItem,
link2 as unknown as RenderLinkItem,
link3 as unknown as RenderLinkItem
)
expect(connector.isInputValidDrop(mockNode, mockInput)).toBe(true)
@@ -88,7 +104,10 @@ describe.skip('LinkConnector', () => {
test('should call the listener when the event is dispatched before reset', () => {
const listener = vi.fn()
const eventData = { renderLinks: [], event: {} as any } // Mock event data
const eventData = {
renderLinks: [],
event: {} as unknown as CanvasPointerEvent
}
connector.listenUntilReset('before-drop-links', listener)
connector.events.dispatch('before-drop-links', eventData)
@@ -120,7 +139,10 @@ describe.skip('LinkConnector', () => {
test('should not call the listener after reset is dispatched', () => {
const listener = vi.fn()
const eventData = { renderLinks: [], event: {} as any }
const eventData = {
renderLinks: [],
event: {} as unknown as CanvasPointerEvent
}
connector.listenUntilReset('before-drop-links', listener)
// Dispatch reset first

View File

@@ -22,12 +22,12 @@ describe('ExecutableGroupNodeChildDTO', () => {
getInputNode: vi.fn(),
getInputLink: vi.fn(),
inputs: []
} as any
} as unknown as LGraphNode
mockInputNode = {
id: '1',
graph: {}
} as any
} as unknown as LGraphNode
// Create the nodesByExecutionId map
mockNodesByExecutionId = new Map()
@@ -46,7 +46,7 @@ describe('ExecutableGroupNodeChildDTO', () => {
origin_slot: 0
}),
inputs: []
} as any
} as unknown as LGraphNode
// External node with ID '1'
const externalNodeDto = {
@@ -81,7 +81,7 @@ describe('ExecutableGroupNodeChildDTO', () => {
getInputNode: vi.fn(),
getInputLink: vi.fn(),
inputs: []
} as any
} as unknown as LGraphNode
// Internal node with ID '10:2'
const internalInputNode = {
@@ -97,10 +97,10 @@ describe('ExecutableGroupNodeChildDTO', () => {
// Internal nodes are stored with just their index
mockNodesByExecutionId.set('2', internalNodeDto)
groupNodeChild.getInputNode.mockReturnValue(internalInputNode)
groupNodeChild.getInputLink.mockReturnValue({
vi.mocked(groupNodeChild.getInputNode).mockReturnValue(internalInputNode)
vi.mocked(groupNodeChild.getInputLink).mockReturnValue({
origin_slot: 1
})
} as unknown as ReturnType<LGraphNode['getInputLink']>)
const dto = new ExecutableGroupNodeChildDTO(
groupNodeChild,
@@ -180,7 +180,7 @@ describe('ExecutableGroupNodeChildDTO', () => {
origin_slot: 0
}),
inputs: []
} as any
} as unknown as LGraphNode
// Create DTO with deeply nested path to simulate group node inside subgraph
const dto = new ExecutableGroupNodeChildDTO(