|
| 1 | +import { it, expectTypeOf } from 'vitest' |
| 2 | +import { assert, _ } from 'spec.ts' |
| 3 | + |
| 4 | +import { interpolate } from './interpolate' |
| 5 | +import { SpringValue } from './SpringValue' |
| 6 | +import { Interpolation } from './Interpolation' |
| 7 | + |
| 8 | +// Revived from the previously-orphaned spec.ts suite in |
| 9 | +// `packages/core/src/types/__tests__/interpolate.ts`. Now co-located and run by |
| 10 | +// the `types` project. Expectations updated: `interpolate` returns an |
| 11 | +// `Interpolation`, not a `SpringValue`. |
| 12 | +// |
| 13 | +// `interpolate` is called inside never-invoked functions so the calls are |
| 14 | +// type-checked by tsc but never executed by Vitest's runtime collection pass. |
| 15 | + |
| 16 | +/** Return the arguments as-is */ |
| 17 | +const args = <T extends ReadonlyArray<any>>(...args: T) => args |
| 18 | + |
| 19 | +it('with one SpringValue', () => { |
| 20 | + function scenario() { |
| 21 | + // Basic value (a single spring value spreads to a readonly array) |
| 22 | + const out1 = interpolate(_ as SpringValue<number>, args) |
| 23 | + assert(out1, _ as Interpolation<readonly number[]>) |
| 24 | + |
| 25 | + // Array value |
| 26 | + const out2 = interpolate(_ as SpringValue<[number, number]>, args) |
| 27 | + assert(out2, _ as Interpolation<[number, number]>) |
| 28 | + } |
| 29 | + expectTypeOf(scenario).toBeFunction() |
| 30 | +}) |
| 31 | + |
| 32 | +it('with an array of SpringValues', () => { |
| 33 | + function scenario() { |
| 34 | + // 1 value |
| 35 | + const out1 = interpolate(_ as [SpringValue<number>], args) |
| 36 | + assert(out1, _ as Interpolation<[number]>) |
| 37 | + |
| 38 | + // 2 values |
| 39 | + const out2 = interpolate( |
| 40 | + _ as [SpringValue<number>, SpringValue<string>], |
| 41 | + args |
| 42 | + ) |
| 43 | + assert(out2, _ as Interpolation<[number, string]>) |
| 44 | + |
| 45 | + // Infinite values |
| 46 | + const out3 = interpolate(_ as SpringValue<number>[], args) |
| 47 | + assert(out3, _ as Interpolation<number[]>) |
| 48 | + } |
| 49 | + expectTypeOf(scenario).toBeFunction() |
| 50 | +}) |
0 commit comments