From f5c9c722346c81038d49233415160aa5b50d1670 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 20 Feb 2026 01:31:03 -0800 Subject: [PATCH] test: refactor widgetUtil tests to use it.for parameterization (#8971) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/utils/widgetUtil.test.ts | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/utils/widgetUtil.test.ts b/src/utils/widgetUtil.test.ts index 8f9eff2e76..122d063af8 100644 --- a/src/utils/widgetUtil.test.ts +++ b/src/utils/widgetUtil.test.ts @@ -14,25 +14,18 @@ describe('getWidgetDefaultValue', () => { expect(getWidgetDefaultValue(spec)).toBe(42) }) - it('returns 0 for INT type without default', () => { - const spec = { type: 'INT' } as InputSpec - expect(getWidgetDefaultValue(spec)).toBe(0) - }) - - it('returns 0 for FLOAT type without default', () => { - const spec = { type: 'FLOAT' } as InputSpec - expect(getWidgetDefaultValue(spec)).toBe(0) - }) - - it('returns false for BOOLEAN type without default', () => { - const spec = { type: 'BOOLEAN' } as InputSpec - expect(getWidgetDefaultValue(spec)).toBe(false) - }) - - it('returns empty string for STRING type without default', () => { - const spec = { type: 'STRING' } as InputSpec - expect(getWidgetDefaultValue(spec)).toBe('') - }) + 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