Files
ComfyUI_frontend/src/platform/nodeReplacement/cnrIdUtil.test.ts
Alexander Brown 661e3d7949 test: migrate as unknown as to @total-typescript/shoehorn (#10761)
*PR Created by the Glary-Bot Agent*

---

## Summary

- Replace all `as unknown as Type` assertions in 59 unit test files with
type-safe `@total-typescript/shoehorn` functions
- Use `fromPartial<Type>()` for partial mock objects where deep-partial
type-checks (21 files)
- Use `fromAny<Type>()` for fundamentally incompatible types: null,
undefined, primitives, variables, class expressions, and mocks with
test-specific extra properties that `PartialDeepObject` rejects
(remaining files)
- All explicit type parameters preserved so TypeScript return types are
correct
- Browser test `.spec.ts` files excluded (shoehorn unavailable in
`page.evaluate` browser context)

## Verification

- `pnpm typecheck` 
- `pnpm lint` 
- `pnpm format` 
- Pre-commit hooks passed (format + oxlint + eslint + typecheck)
- Migrated test files verified passing (ran representative subset)
- No test behavior changes — only type assertion syntax changed
- No UI changes — screenshots not applicable

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-10761-test-migrate-as-unknown-as-to-total-typescript-shoehorn-3336d73d365081f6b8adc44db5dcc380)
by [Unito](https://www.unito.io)

---------

Co-authored-by: Glary-Bot <glary-bot@users.noreply.github.com>
Co-authored-by: Amp <amp@ampcode.com>
2026-03-30 19:20:18 -07:00

68 lines
2.1 KiB
TypeScript

import { fromAny } from '@total-typescript/shoehorn'
import { describe, expect, it } from 'vitest'
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { getCnrIdFromNode, getCnrIdFromProperties } from './cnrIdUtil'
describe('getCnrIdFromProperties', () => {
it('returns cnr_id when present', () => {
expect(getCnrIdFromProperties({ cnr_id: 'my-pack' })).toBe('my-pack')
})
it('returns aux_id when cnr_id is absent', () => {
expect(getCnrIdFromProperties({ aux_id: 'my-aux-pack' })).toBe(
'my-aux-pack'
)
})
it('prefers cnr_id over aux_id', () => {
expect(
getCnrIdFromProperties({ cnr_id: 'primary', aux_id: 'secondary' })
).toBe('primary')
})
it('returns undefined when neither is present', () => {
expect(getCnrIdFromProperties({})).toBeUndefined()
})
it('returns undefined for null properties', () => {
expect(getCnrIdFromProperties(null)).toBeUndefined()
})
it('returns undefined for undefined properties', () => {
expect(getCnrIdFromProperties(undefined)).toBeUndefined()
})
it('returns undefined when cnr_id is not a string', () => {
expect(getCnrIdFromProperties({ cnr_id: 123 })).toBeUndefined()
})
})
describe('getCnrIdFromNode', () => {
it('returns cnr_id from node properties', () => {
const node = fromAny<LGraphNode, unknown>({
properties: { cnr_id: 'node-pack' }
})
expect(getCnrIdFromNode(node)).toBe('node-pack')
})
it('returns aux_id when cnr_id is absent', () => {
const node = fromAny<LGraphNode, unknown>({
properties: { aux_id: 'node-aux-pack' }
})
expect(getCnrIdFromNode(node)).toBe('node-aux-pack')
})
it('prefers cnr_id over aux_id in node properties', () => {
const node = fromAny<LGraphNode, unknown>({
properties: { cnr_id: 'primary', aux_id: 'secondary' }
})
expect(getCnrIdFromNode(node)).toBe('primary')
})
it('returns undefined when node has no cnr_id or aux_id', () => {
const node = fromAny<LGraphNode, unknown>({ properties: {} })
expect(getCnrIdFromNode(node)).toBeUndefined()
})
})