Skip to content

Commit 7d81799

Browse files
test: add type compiler tests for CodeBlock
1 parent 5dc4da7 commit 7d81799

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, expectTypeOf, it } from 'vitest';
2+
import React from 'react';
3+
import { CodeBlock } from './code-block';
4+
5+
type CodeBlockProps = React.ComponentProps<typeof CodeBlock>;
6+
7+
describe('CodeBlock Type Compiler Validation', () => {
8+
it('maintains expected props structure', () => {
9+
expectTypeOf<CodeBlockProps>().toEqualTypeOf<{
10+
code: string;
11+
}>();
12+
});
13+
14+
it('accepts valid prop values', () => {
15+
const props: CodeBlockProps = {
16+
code: 'console.log("Hello");',
17+
};
18+
19+
expectTypeOf(props).toEqualTypeOf<CodeBlockProps>();
20+
});
21+
22+
it('rejects invalid code prop type', () => {
23+
const invalid: CodeBlockProps = {
24+
// @ts-expect-error code must be a string
25+
code: 123,
26+
};
27+
28+
void invalid;
29+
});
30+
31+
it('returns a valid React element', () => {
32+
const element = <CodeBlock code="const a = 1;" />;
33+
34+
expectTypeOf(element).toMatchTypeOf<React.ReactElement>();
35+
});
36+
37+
it('enforces strict property configuration', () => {
38+
expectTypeOf<keyof CodeBlockProps>().toEqualTypeOf<'code'>();
39+
});
40+
});

0 commit comments

Comments
 (0)