Skip to content

Commit 0b68d01

Browse files
test(template): add type compiler validation tests
1 parent ad20362 commit 0b68d01

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { describe, expect, it, expectTypeOf } from 'vitest';
3+
import { render, screen } from '@testing-library/react';
4+
import Template from './template';
5+
6+
describe('Template type compiler validation', () => {
7+
it('should enforce children prop as ReactNode', () => {
8+
type TemplateProps = React.ComponentProps<typeof Template>;
9+
10+
expectTypeOf<TemplateProps>().toMatchTypeOf<{
11+
children: React.ReactNode;
12+
}>();
13+
});
14+
15+
it('should allow optional ReactNode-compatible child values', () => {
16+
type TemplateProps = React.ComponentProps<typeof Template>;
17+
18+
expectTypeOf<TemplateProps['children']>().toMatchTypeOf<React.ReactNode>();
19+
});
20+
21+
it('should block invalid prop parameters during static type checking', () => {
22+
type TemplateProps = React.ComponentProps<typeof Template>;
23+
24+
expectTypeOf<TemplateProps>().not.toMatchTypeOf<{
25+
invalidProp: string;
26+
}>();
27+
});
28+
29+
it('should render valid children without schema violations', () => {
30+
render(
31+
<Template>
32+
<div>Template Child</div>
33+
</Template>
34+
);
35+
36+
expect(screen.getByText('Template Child')).toBeTruthy();
37+
});
38+
39+
it('should accept null children without compile errors', () => {
40+
render(<Template>{null}</Template>);
41+
42+
expect(true).toBe(true);
43+
});
44+
});

0 commit comments

Comments
 (0)