From dd17fcf8c6287c5800ff8b5680d544093aa4099e Mon Sep 17 00:00:00 2001 From: Connor Byrne Date: Wed, 13 May 2026 13:45:37 -0700 Subject: [PATCH] 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 --- src/services/litegraphService.test.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/services/litegraphService.test.ts b/src/services/litegraphService.test.ts index 62231fabec..536f6937d0 100644 --- a/src/services/litegraphService.test.ts +++ b/src/services/litegraphService.test.ts @@ -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 = {}): 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(