refactor: remove any types from LGraphNode.test.ts

- Define NodeConstructorWithSlotOffset interface for constructor with optional slot_start_y
- Replace 3 'as any' casts with proper double-cast pattern
- All instances related to dynamic slot_start_y property on node constructor
This commit is contained in:
Johnpaul
2026-01-21 21:03:29 +01:00
parent 6219bb54af
commit 72ed73dead

View File

@@ -15,6 +15,10 @@ import {
import { test } from './__fixtures__/testExtensions'
interface NodeConstructorWithSlotOffset {
slot_start_y?: number
}
function getMockISerialisedNode(
data: Partial<ISerialisedNode>
): ISerialisedNode {
@@ -632,7 +636,9 @@ describe('LGraphNode', () => {
}
node.inputs = [inputSlot, inputSlot2]
const slotIndex = 0
const nodeOffsetY = (node.constructor as any).slot_start_y || 0
const nodeOffsetY =
(node.constructor as unknown as NodeConstructorWithSlotOffset)
.slot_start_y || 0
const expectedY =
200 + (slotIndex + 0.7) * LiteGraph.NODE_SLOT_HEIGHT + nodeOffsetY
const expectedX = 100 + LiteGraph.NODE_SLOT_HEIGHT * 0.5
@@ -644,7 +650,9 @@ describe('LGraphNode', () => {
})
test('should return default vertical position including slot_start_y when defined', () => {
;(node.constructor as any).slot_start_y = 25
;(
node.constructor as unknown as NodeConstructorWithSlotOffset
).slot_start_y = 25
node.flags.collapsed = false
node.inputs = [inputSlot]
const slotIndex = 0
@@ -653,7 +661,8 @@ describe('LGraphNode', () => {
200 + (slotIndex + 0.7) * LiteGraph.NODE_SLOT_HEIGHT + nodeOffsetY
const expectedX = 100 + LiteGraph.NODE_SLOT_HEIGHT * 0.5
expect(node.getInputSlotPos(inputSlot)).toEqual([expectedX, expectedY])
delete (node.constructor as any).slot_start_y
delete (node.constructor as unknown as NodeConstructorWithSlotOffset)
.slot_start_y
})
test('should not overwrite onMouseDown prototype', () => {
expect(Object.prototype.hasOwnProperty.call(node, 'onMouseDown')).toEqual(