Files
ComfyUI_frontend/src/utils/widgetUtil.test.ts
Christian Byrne f5c9c72234 test: refactor widgetUtil tests to use it.for parameterization (#8971)
Fixes #8888

Refactors repetitive test cases in `widgetUtil.test.ts` to use Vitest's
`it.for` syntax for parameterized testing. Tests that follow the same
"returns default for type" pattern are consolidated while keeping unique
test cases separate.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8971-test-refactor-widgetUtil-tests-to-use-it-for-parameterization-30c6d73d365081a48e2ecf52bb7b0f98)
by [Unito](https://www.unito.io)
2026-02-20 01:31:03 -08:00

40 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { getWidgetDefaultValue } from '@/utils/widgetUtil'
describe('getWidgetDefaultValue', () => {
it('returns undefined for undefined spec', () => {
expect(getWidgetDefaultValue(undefined)).toBeUndefined()
})
it('returns explicit default when provided', () => {
const spec = { type: 'INT', default: 42 } as InputSpec
expect(getWidgetDefaultValue(spec)).toBe(42)
})
it.for([
{ type: 'INT', expected: 0 },
{ type: 'FLOAT', expected: 0 },
{ type: 'BOOLEAN', expected: false },
{ type: 'STRING', expected: '' }
])(
'returns $expected for $type type without default',
({ type, expected }) => {
const spec = { type } as InputSpec
expect(getWidgetDefaultValue(spec)).toBe(expected)
}
)
it('returns first option for array options without default', () => {
const spec = { type: 'COMBO', options: ['a', 'b', 'c'] } as InputSpec
expect(getWidgetDefaultValue(spec)).toBe('a')
})
it('returns undefined for unknown type without options', () => {
const spec = { type: 'CUSTOM' } as InputSpec
expect(getWidgetDefaultValue(spec)).toBeUndefined()
})
})