66
77import { describe , it , expect , vi } from 'vitest' ;
88import { useState , useEffect } from 'react' ;
9- import { renderHook } from './render.js' ;
9+ import { Text } from 'ink' ;
10+ import { renderHook , render } from './render.js' ;
11+ import { waitFor } from './async.js' ;
12+
13+ describe ( 'render' , ( ) => {
14+ it ( 'should render a component' , ( ) => {
15+ const { lastFrame } = render ( < Text > Hello World</ Text > ) ;
16+ expect ( lastFrame ( ) ) . toBe ( 'Hello World' ) ;
17+ } ) ;
18+
19+ it ( 'should support rerender' , ( ) => {
20+ const { lastFrame, rerender } = render ( < Text > Hello</ Text > ) ;
21+ expect ( lastFrame ( ) ) . toBe ( 'Hello' ) ;
22+
23+ rerender ( < Text > World</ Text > ) ;
24+ expect ( lastFrame ( ) ) . toBe ( 'World' ) ;
25+ } ) ;
26+
27+ it ( 'should support unmount' , ( ) => {
28+ const cleanup = vi . fn ( ) ;
29+ function TestComponent ( ) {
30+ useEffect ( ( ) => cleanup , [ ] ) ;
31+ return < Text > Hello</ Text > ;
32+ }
33+
34+ const { unmount } = render ( < TestComponent /> ) ;
35+ unmount ( ) ;
36+
37+ expect ( cleanup ) . toHaveBeenCalled ( ) ;
38+ } ) ;
39+ } ) ;
1040
1141describe ( 'renderHook' , ( ) => {
1242 it ( 'should rerender with previous props when called without arguments' , async ( ) => {
@@ -23,19 +53,19 @@ describe('renderHook', () => {
2353 } ) ;
2454
2555 expect ( result . current . value ) . toBe ( 1 ) ;
26- await vi . waitFor ( ( ) => expect ( result . current . count ) . toBe ( 1 ) ) ;
56+ await waitFor ( ( ) => expect ( result . current . count ) . toBe ( 1 ) ) ;
2757
2858 // Rerender with new props
2959 rerender ( { value : 2 } ) ;
3060 expect ( result . current . value ) . toBe ( 2 ) ;
31- await vi . waitFor ( ( ) => expect ( result . current . count ) . toBe ( 2 ) ) ;
61+ await waitFor ( ( ) => expect ( result . current . count ) . toBe ( 2 ) ) ;
3262
3363 // Rerender without arguments should use previous props (value: 2)
3464 // This would previously crash or pass undefined if not fixed
3565 rerender ( ) ;
3666 expect ( result . current . value ) . toBe ( 2 ) ;
3767 // Count should not increase because value didn't change
38- await vi . waitFor ( ( ) => expect ( result . current . count ) . toBe ( 2 ) ) ;
68+ await waitFor ( ( ) => expect ( result . current . count ) . toBe ( 2 ) ) ;
3969 } ) ;
4070
4171 it ( 'should handle initial render without props' , ( ) => {
0 commit comments