Skip to content

Commit ffd5698

Browse files
Add type compiler validation tests for GitHubUserValidator (fixes JhaSourav07#2962)
1 parent 2e604a1 commit ffd5698

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { describe, expectTypeOf, it } from 'vitest';
2+
import { GitHubUserValidator } from './validate-user';
3+
4+
type ValidateUserReturn = ReturnType<GitHubUserValidator['validateUser']>;
5+
6+
describe('TypeScript Compiler Validation & Schema Constraints Stability', () => {
7+
it('enforces correct parameter and return types for validateUser', () => {
8+
expectTypeOf<GitHubUserValidator['validateUser']>().parameters.toEqualTypeOf<
9+
[username: string]
10+
>();
11+
expectTypeOf<ValidateUserReturn>().toEqualTypeOf<Promise<boolean>>();
12+
});
13+
14+
it('validates singleton instance pattern returns correct type', () => {
15+
expectTypeOf<
16+
ReturnType<(typeof GitHubUserValidator)['getInstance']>
17+
>().toEqualTypeOf<GitHubUserValidator>();
18+
});
19+
20+
it('validates reset method returns void', () => {
21+
expectTypeOf<GitHubUserValidator['reset']>().returns.toBeVoid();
22+
});
23+
24+
it('blocks invalid parameter types from being accepted by validateUser parameter type', () => {
25+
expectTypeOf<GitHubUserValidator['validateUser']>().parameters.toEqualTypeOf<
26+
[username: string]
27+
>();
28+
29+
// These type assertions ensure that only string is accepted:
30+
expectTypeOf<number>().not.toMatchTypeOf<string>();
31+
expectTypeOf<object>().not.toMatchTypeOf<string>();
32+
expectTypeOf<null>().not.toMatchTypeOf<string>();
33+
expectTypeOf<undefined>().not.toMatchTypeOf<string>();
34+
});
35+
36+
it('verifies schema validation constraints return strict validation reports', () => {
37+
expectTypeOf<ValidateUserReturn>().toEqualTypeOf<Promise<boolean>>();
38+
});
39+
});

0 commit comments

Comments
 (0)