@@ -9,9 +9,19 @@ import { OverflowProvider } from '../../contexts/OverflowContext.js';
99import { MaxSizedBox } from './MaxSizedBox.js' ;
1010import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js' ;
1111import { Box , Text } from 'ink' ;
12- import { describe , it , expect } from 'vitest' ;
12+ import { act } from 'react' ;
13+ import { describe , it , expect , beforeEach , afterEach , vi } from 'vitest' ;
1314
1415describe ( '<MaxSizedBox />' , ( ) => {
16+ beforeEach ( ( ) => {
17+ vi . useFakeTimers ( ) ;
18+ } ) ;
19+
20+ afterEach ( ( ) => {
21+ vi . useRealTimers ( ) ;
22+ vi . restoreAllMocks ( ) ;
23+ } ) ;
24+
1525 it ( 'renders children without truncation when they fit' , async ( ) => {
1626 const { lastFrame, waitUntilReady, unmount } = render (
1727 < OverflowProvider >
@@ -22,6 +32,9 @@ describe('<MaxSizedBox />', () => {
2232 </ MaxSizedBox >
2333 </ OverflowProvider > ,
2434 ) ;
35+ await act ( async ( ) => {
36+ vi . runAllTimers ( ) ;
37+ } ) ;
2538 await waitUntilReady ( ) ;
2639 expect ( lastFrame ( ) ) . toContain ( 'Hello, World!' ) ;
2740 expect ( lastFrame ( ) ) . toMatchSnapshot ( ) ;
@@ -40,6 +53,9 @@ describe('<MaxSizedBox />', () => {
4053 </ MaxSizedBox >
4154 </ OverflowProvider > ,
4255 ) ;
56+ await act ( async ( ) => {
57+ vi . runAllTimers ( ) ;
58+ } ) ;
4359 await waitUntilReady ( ) ;
4460 expect ( lastFrame ( ) ) . toContain (
4561 '... first 2 lines hidden (Ctrl+O to show) ...' ,
@@ -60,6 +76,9 @@ describe('<MaxSizedBox />', () => {
6076 </ MaxSizedBox >
6177 </ OverflowProvider > ,
6278 ) ;
79+ await act ( async ( ) => {
80+ vi . runAllTimers ( ) ;
81+ } ) ;
6382 await waitUntilReady ( ) ;
6483 expect ( lastFrame ( ) ) . toContain (
6584 '... last 2 lines hidden (Ctrl+O to show) ...' ,
@@ -80,6 +99,9 @@ describe('<MaxSizedBox />', () => {
8099 </ MaxSizedBox >
81100 </ OverflowProvider > ,
82101 ) ;
102+ await act ( async ( ) => {
103+ vi . runAllTimers ( ) ;
104+ } ) ;
83105 await waitUntilReady ( ) ;
84106 expect ( lastFrame ( ) ) . toContain (
85107 '... first 2 lines hidden (Ctrl+O to show) ...' ,
@@ -98,6 +120,9 @@ describe('<MaxSizedBox />', () => {
98120 </ MaxSizedBox >
99121 </ OverflowProvider > ,
100122 ) ;
123+ await act ( async ( ) => {
124+ vi . runAllTimers ( ) ;
125+ } ) ;
101126 await waitUntilReady ( ) ;
102127 expect ( lastFrame ( ) ) . toContain (
103128 '... first 1 line hidden (Ctrl+O to show) ...' ,
@@ -118,6 +143,9 @@ describe('<MaxSizedBox />', () => {
118143 </ MaxSizedBox >
119144 </ OverflowProvider > ,
120145 ) ;
146+ await act ( async ( ) => {
147+ vi . runAllTimers ( ) ;
148+ } ) ;
121149 await waitUntilReady ( ) ;
122150 expect ( lastFrame ( ) ) . toContain (
123151 '... first 7 lines hidden (Ctrl+O to show) ...' ,
@@ -137,6 +165,9 @@ describe('<MaxSizedBox />', () => {
137165 </ OverflowProvider > ,
138166 ) ;
139167
168+ await act ( async ( ) => {
169+ vi . runAllTimers ( ) ;
170+ } ) ;
140171 await waitUntilReady ( ) ;
141172 expect ( lastFrame ( ) ) . toContain ( 'This is a' ) ;
142173 expect ( lastFrame ( ) ) . toMatchSnapshot ( ) ;
@@ -154,6 +185,9 @@ describe('<MaxSizedBox />', () => {
154185 </ MaxSizedBox >
155186 </ OverflowProvider > ,
156187 ) ;
188+ await act ( async ( ) => {
189+ vi . runAllTimers ( ) ;
190+ } ) ;
157191 await waitUntilReady ( ) ;
158192 expect ( lastFrame ( ) ) . toContain ( 'Line 1' ) ;
159193 expect ( lastFrame ( ) ) . toMatchSnapshot ( ) ;
@@ -166,6 +200,9 @@ describe('<MaxSizedBox />', () => {
166200 < MaxSizedBox maxWidth = { 80 } maxHeight = { 10 } > </ MaxSizedBox >
167201 </ OverflowProvider > ,
168202 ) ;
203+ await act ( async ( ) => {
204+ vi . runAllTimers ( ) ;
205+ } ) ;
169206 await waitUntilReady ( ) ;
170207 expect ( lastFrame ( { allowEmpty : true } ) ?. trim ( ) ) . equals ( '' ) ;
171208 unmount ( ) ;
@@ -185,6 +222,9 @@ describe('<MaxSizedBox />', () => {
185222 </ MaxSizedBox >
186223 </ OverflowProvider > ,
187224 ) ;
225+ await act ( async ( ) => {
226+ vi . runAllTimers ( ) ;
227+ } ) ;
188228 await waitUntilReady ( ) ;
189229 expect ( lastFrame ( ) ) . toContain ( 'Line 1 from Fragment' ) ;
190230 expect ( lastFrame ( ) ) . toMatchSnapshot ( ) ;
@@ -206,6 +246,9 @@ describe('<MaxSizedBox />', () => {
206246 </ OverflowProvider > ,
207247 ) ;
208248
249+ await act ( async ( ) => {
250+ vi . runAllTimers ( ) ;
251+ } ) ;
209252 await waitUntilReady ( ) ;
210253 expect ( lastFrame ( ) ) . toContain (
211254 '... first 21 lines hidden (Ctrl+O to show) ...' ,
@@ -229,6 +272,9 @@ describe('<MaxSizedBox />', () => {
229272 </ OverflowProvider > ,
230273 ) ;
231274
275+ await act ( async ( ) => {
276+ vi . runAllTimers ( ) ;
277+ } ) ;
232278 await waitUntilReady ( ) ;
233279 expect ( lastFrame ( ) ) . toContain (
234280 '... last 21 lines hidden (Ctrl+O to show) ...' ,
@@ -253,6 +299,9 @@ describe('<MaxSizedBox />', () => {
253299 { width : 80 } ,
254300 ) ;
255301
302+ await act ( async ( ) => {
303+ vi . runAllTimers ( ) ;
304+ } ) ;
256305 await waitUntilReady ( ) ;
257306 expect ( lastFrame ( ) ) . toContain ( '... last' ) ;
258307
0 commit comments