From 911b4bcb1fb1b68c04610f1ef9cabb7b947f5bf0 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Sat, 5 Sep 2026 00:33:57 +0000 Subject: [PATCH] [Tests] Add coverage for PickByPrefix type helper Add unit tests for the PickByPrefix TypeScript type helper to test prefix key matching, explicit key inclusions, and non-matching key edge cases. --- .../public/common/ts/pick-by-prefix.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 packages/cli-kit/src/public/common/ts/pick-by-prefix.test.ts diff --git a/packages/cli-kit/src/public/common/ts/pick-by-prefix.test.ts b/packages/cli-kit/src/public/common/ts/pick-by-prefix.test.ts new file mode 100644 index 00000000000..de535dc4de5 --- /dev/null +++ b/packages/cli-kit/src/public/common/ts/pick-by-prefix.test.ts @@ -0,0 +1,47 @@ +import {PickByPrefix} from './pick-by-prefix.js' +import {describe, expectTypeOf, test} from 'vitest' + +describe('PickByPrefix', () => { + test('picks keys matching a prefix', () => { + interface Source { + foo_one: number + foo_two: string + bar_one: boolean + } + + type Result = PickByPrefix + + expectTypeOf().toEqualTypeOf<{ + foo_one: number + foo_two: string + }>() + }) + + test('picks keys matching a prefix and explicitly included keys', () => { + interface Source { + foo_one: number + foo_two: string + bar_one: boolean + extra: string + } + + type Result = PickByPrefix + + expectTypeOf().toEqualTypeOf<{ + foo_one: number + foo_two: string + extra: string + }>() + }) + + test('returns empty object type when no keys match prefix or extra keys', () => { + interface Source { + bar_one: boolean + baz_two: number + } + + type Result = PickByPrefix + + expectTypeOf().toEqualTypeOf<{}>() + }) +})