|
| 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