File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments