Skip to content

Commit 2472938

Browse files
test(svg-constants-type-compiler): verify TypeScript Compiler Validation & Schema Constraints Stability
1 parent e3369ea commit 2472938

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)