Road to No explicit any Part 8 (Group 3): Improve type safety in Group 3 test mocks (#8304)

## Summary

- Eliminated all `as unknown as` type assertions from Group 3 test files
- Created reusable factory functions in `litegraphTestUtils.ts` for
better type safety
- Improved test mock composition using `Partial` types with single `as`
casts
- Fixed LGraphNode tests to use proper API methods instead of direct
property assignment

## Changes by Category

### New Factory Functions in `litegraphTestUtils.ts`

- `createMockLGraphNodeWithArrayBoundingRect()` - Creates LGraphNode
with proper boundingRect for position tests
- `createMockFileList()` - Creates mock FileList with proper structure
including `item()` method

### Test File Improvements

**Composables:**
- `useLoad3dDrag.test.ts` - Used `createMockFileList` factory
- `useLoad3dViewer.test.ts` - Created local `MockSceneManager` interface
with proper typing

**LiteGraph Tests:**
- `LGraphNode.test.ts` - Replaced direct `boundingRect` assignments with
`updateArea()` calls
- `LinkConnector.test.ts` - Improved mock composition with proper
Partial types
- `ToOutputRenderLink.test.ts` - Added `MockEvents` interface for
type-safe event mocking
- Updated integration and core tests to use new factory functions

**Extension Tests:**
- `contextMenuFilter.test.ts` - Updated menu factories to accept
`(IContextMenuValue | null)[]`

## Type Safety Improvements

- Zero `as unknown as` instances (was: multiple instances across 17
files)
- All mocks use proper `Partial<T>` composition with single `as T` casts
- Improved IntelliSense and type checking in test files
- Centralized mock creation reduces duplication and improves
maintainability

## Test Plan

-  All TypeScript type checks pass
-  ESLint passes with no new errors  
-  Pre-commit hooks (format, lint, typecheck) all pass
-  Knip unused export check passes
-  No behavioral changes to actual tests (only type improvements)

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8304-Road-to-No-explicit-any-Improve-type-safety-in-Group-3-test-mocks-2f36d73d365081ab841de96e5f01306d)
by [Unito](https://www.unito.io)
This commit is contained in:
Johnpaul Chiwetelu
2026-01-26 18:13:18 +01:00
committed by GitHub
parent ba5380395d
commit 29220f6562
17 changed files with 606 additions and 355 deletions

View File

@@ -3,6 +3,7 @@ import { ref } from 'vue'
import { useLoad3dDrag } from '@/composables/useLoad3dDrag'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { createMockFileList } from '@/utils/__tests__/litegraphTestUtils'
vi.mock('@/platform/updates/common/toastStore', () => ({
useToastStore: vi.fn()
@@ -19,22 +20,22 @@ function createMockDragEvent(
const files = options.files || []
const types = options.hasFiles ? ['Files'] : []
const dataTransfer = {
const dataTransfer: Partial<DataTransfer> = {
types,
files,
files: createMockFileList(files),
dropEffect: 'none' as DataTransfer['dropEffect']
}
const event = {
const event: Partial<DragEvent> = {
type,
dataTransfer
} as unknown as DragEvent
dataTransfer: dataTransfer as DataTransfer
}
return event
return event as DragEvent
}
describe('useLoad3dDrag', () => {
let mockToastStore: any
let mockToastStore: ReturnType<typeof useToastStore>
let mockOnModelDrop: (file: File) => void | Promise<void>
beforeEach(() => {
@@ -42,7 +43,9 @@ describe('useLoad3dDrag', () => {
mockToastStore = {
addAlert: vi.fn()
}
} as Partial<ReturnType<typeof useToastStore>> as ReturnType<
typeof useToastStore
>
vi.mocked(useToastStore).mockReturnValue(mockToastStore)
mockOnModelDrop = vi.fn()