11import { renderHook , waitFor } from '@testing-library/react' ;
2- import type { FC } from 'react' ;
2+ import { act , type FC } from 'react' ;
33import { vi } from 'vitest' ;
44
55import { DualScrollSyncContent } from '@/components/DualScrollSync/DualScrollSyncContent' ;
@@ -22,17 +22,20 @@ describe('useValidateChildren', () => {
2222 warnSpy . mockRestore ( ) ;
2323 } ) ;
2424
25- it ( 'should not log warnings when items prop is provided' , ( ) => {
25+ it ( 'should not log warnings when items prop is provided' , async ( ) => {
2626 const items = [
2727 { sectionKey : 'section1' , label : 'Section 1' , children : < div > Content 1</ div > } ,
2828 { sectionKey : 'section2' , label : 'Section 2' , children : < div > Content 2</ div > }
2929 ] ;
3030
31- renderHook ( ( ) => useValidateChildren ( { items, children : null } ) ) ;
32- expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
31+ act ( ( ) => renderHook ( ( ) => useValidateChildren ( { items, children : null } ) ) ) ;
32+
33+ await waitFor ( ( ) => {
34+ expect ( warnSpy ) . toHaveBeenCalledTimes ( 0 ) ;
35+ } ) ;
3336 } ) ;
3437
35- it ( 'should not log warnings when NavItems and ContentSections match' , ( ) => {
38+ it ( 'should not log warnings when NavItems and ContentSections match' , async ( ) => {
3639 const children = (
3740 < >
3841 < DualScrollSyncNav >
@@ -46,8 +49,11 @@ describe('useValidateChildren', () => {
4649 </ >
4750 ) ;
4851
49- renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ;
50- expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
52+ act ( ( ) => renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ) ;
53+
54+ await waitFor ( ( ) => {
55+ expect ( warnSpy ) . toHaveBeenCalledTimes ( 0 ) ;
56+ } ) ;
5157 } ) ;
5258
5359 it ( 'should log warnings for missing ContentSections' , async ( ) => {
@@ -63,7 +69,7 @@ describe('useValidateChildren', () => {
6369 </ >
6470 ) ;
6571
66- renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ;
72+ act ( ( ) => renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ) ;
6773
6874 await waitFor ( ( ) => {
6975 expect ( warnSpy ) . toHaveBeenCalledWith (
@@ -85,7 +91,7 @@ describe('useValidateChildren', () => {
8591 </ >
8692 ) ;
8793
88- renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ;
94+ act ( ( ) => renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ) ;
8995
9096 await waitFor ( ( ) => {
9197 expect ( warnSpy ) . toHaveBeenCalledWith ( '[DualScrollSync] Missing NavItem for "section2"' ) ;
@@ -107,7 +113,7 @@ describe('useValidateChildren', () => {
107113 </ div >
108114 ) ;
109115
110- renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ;
116+ act ( ( ) => renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ) ;
111117
112118 await waitFor ( ( ) => {
113119 expect ( warnSpy ) . toHaveBeenCalledWith (
@@ -116,10 +122,13 @@ describe('useValidateChildren', () => {
116122 } ) ;
117123 } ) ;
118124
119- it ( 'should not log warnings for string children' , ( ) => {
125+ it ( 'should not log warnings for string children' , async ( ) => {
120126 const children = < span > Hello World</ span > ;
121127
122- renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ;
123- expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
128+ act ( ( ) => renderHook ( ( ) => useValidateChildren ( { children, items : undefined } ) ) ) ;
129+
130+ await waitFor ( ( ) => {
131+ expect ( warnSpy ) . toHaveBeenCalledTimes ( 0 ) ;
132+ } ) ;
124133 } ) ;
125134} ) ;
0 commit comments