|
| 1 | +import { describe, expectTypeOf, it } from 'vitest'; |
| 2 | +import { |
| 3 | + CONTRIBUTION_MILESTONES, |
| 4 | + FONT_MAP, |
| 5 | + GHOST_HEIGHT_PX, |
| 6 | + LINEAR_SCALE_MULTIPLIER, |
| 7 | + LOG_SCALE_MULTIPLIER, |
| 8 | + MAX_LINEAR_HEIGHT, |
| 9 | + MAX_LOG_HEIGHT, |
| 10 | + SVG_HEIGHT, |
| 11 | + SVG_WIDTH, |
| 12 | +} from './constants'; |
| 13 | + |
| 14 | +describe('lib/svg/constants — TypeScript type compiler', () => { |
| 15 | + it('numeric dimension constants are typed as number', () => { |
| 16 | + expectTypeOf(SVG_WIDTH).toBeNumber(); |
| 17 | + expectTypeOf(SVG_HEIGHT).toBeNumber(); |
| 18 | + expectTypeOf(GHOST_HEIGHT_PX).toBeNumber(); |
| 19 | + expectTypeOf(MAX_LOG_HEIGHT).toBeNumber(); |
| 20 | + expectTypeOf(MAX_LINEAR_HEIGHT).toBeNumber(); |
| 21 | + }); |
| 22 | + |
| 23 | + it('scale multiplier constants are typed as number', () => { |
| 24 | + expectTypeOf(LOG_SCALE_MULTIPLIER).toBeNumber(); |
| 25 | + expectTypeOf(LINEAR_SCALE_MULTIPLIER).toBeNumber(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('FONT_MAP satisfies Record<string, string> — keys and values are both strings', () => { |
| 29 | + expectTypeOf(FONT_MAP).toEqualTypeOf<Record<string, string>>(); |
| 30 | + expectTypeOf(FONT_MAP).not.toEqualTypeOf<Record<string, number>>(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('CONTRIBUTION_MILESTONES satisfies a readonly number array and its elements are numbers', () => { |
| 34 | + expectTypeOf(CONTRIBUTION_MILESTONES).toEqualTypeOf<number[]>(); |
| 35 | + expectTypeOf(CONTRIBUTION_MILESTONES).items.toBeNumber(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('a function accepting number accepts all numeric constants without type errors', () => { |
| 39 | + const requiresNumber = (n: number): number => n; |
| 40 | + |
| 41 | + expectTypeOf(requiresNumber).parameter(0).toBeNumber(); |
| 42 | + // Verify each constant satisfies the number parameter type |
| 43 | + expectTypeOf(SVG_WIDTH).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>(); |
| 44 | + expectTypeOf(SVG_HEIGHT).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>(); |
| 45 | + expectTypeOf(LOG_SCALE_MULTIPLIER).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>(); |
| 46 | + expectTypeOf(LINEAR_SCALE_MULTIPLIER).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>(); |
| 47 | + }); |
| 48 | +}); |
0 commit comments