fix: use real LGraphNode instance in createMockNode fixture

Instead of using `as unknown as LGraphNode` type assertion, instantiate
a real LGraphNode and assign test-specific overrides. This eliminates
the type escape at the fixture level while maintaining test flexibility.

Addresses review feedback:
https://github.com/Comfy-Org/ComfyUI_frontend/pull/11397#discussion_r3186572593

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Connor Byrne
2026-05-13 13:45:37 -07:00
parent cfc65bda75
commit dd17fcf8c6

View File

@@ -1,9 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type {
IContextMenuValue,
LGraphNode
} from '@/lib/litegraph/src/litegraph'
import type { IContextMenuValue } from '@/lib/litegraph/src/litegraph'
import { LGraphNode } from '@/lib/litegraph/src/litegraph'
import type { ContextMenuDivElement } from '@/lib/litegraph/src/interfaces'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
@@ -247,14 +245,19 @@ vi.mock('@/stores/nodeDefStore', () => ({
}))
function createMockNode(overrides: Record<string, unknown> = {}): LGraphNode {
return {
const node = new LGraphNode('TestNode')
Object.assign(node, {
id: 1,
inputs: [],
graph: null,
constructor: { nodeData: { name: 'TestNode' } },
getWidgetOnPos: vi.fn(),
...overrides
} as unknown as LGraphNode
getWidgetOnPos: vi.fn()
})
Object.assign(node, overrides)
// Set static nodeData for tests that check constructor.nodeData
;(node.constructor as { nodeData?: { name: string } }).nodeData = {
name: 'TestNode'
}
return node
}
function createMockWidget(