77  screen , 
88  waitFor , 
99}  from  '@testing-library/react' ; 
10- import  {  createContainer ,  getHtml ,   sleep  }  from  './util' ; 
10+ import  {  createContainer ,  getHtml  }  from  './util' ; 
1111
1212describe ( 'bridge' ,  ( )  =>  { 
1313  let  containerInfo : ReturnType < typeof  createContainer > ; 
@@ -31,17 +31,28 @@ describe('bridge', () => {
3131      dom : containerInfo ?. container , 
3232    } ) ; 
3333
34-     await  sleep ( 200 ) ; 
35-     expect ( document . querySelector ( '#container' ) ! . innerHTML ) . toContain ( 
36-       '<div>life cycle render</div>' , 
34+     await  waitFor ( 
35+       ( )  =>  { 
36+         expect ( document . querySelector ( '#container' ) ?. innerHTML ) . toContain ( 
37+           '<div>life cycle render</div>' , 
38+         ) ; 
39+       } , 
40+       {  timeout : 2000  } , 
3741    ) ; 
3842
3943    lifeCycle . destroy ( { 
4044      dom : containerInfo ?. container , 
4145      moduleName : 'test' , 
4246    } ) ; 
4347
44-     expect ( document . querySelector ( '#container' ) ! . innerHTML ) . toContain ( '' ) ; 
48+     await  waitFor ( 
49+       ( )  =>  { 
50+         expect ( 
51+           ( document . querySelector ( '#container' ) ?. innerHTML  ||  '' ) . trim ( ) , 
52+         ) . toBe ( '' ) ; 
53+       } , 
54+       {  timeout : 2000  } , 
55+     ) ; 
4556  } ) ; 
4657
4758  it ( 'createRemoteAppComponent' ,  async  ( )  =>  { 
@@ -66,9 +77,13 @@ describe('bridge', () => {
6677    ) ; 
6778    expect ( getHtml ( container ) ) . toMatch ( 'loading' ) ; 
6879
69-     await  sleep ( 200 ) ; 
70-     expect ( getHtml ( container ) ) . toMatch ( 'life cycle render' ) ; 
71-     expect ( getHtml ( container ) ) . toMatch ( 'hello world' ) ; 
80+     await  waitFor ( 
81+       ( )  =>  { 
82+         expect ( getHtml ( container ) ) . toMatch ( 'life cycle render' ) ; 
83+         expect ( getHtml ( container ) ) . toMatch ( 'hello world' ) ; 
84+       } , 
85+       {  timeout : 2000  } , 
86+     ) ; 
7287  } ) ; 
7388
7489  it ( 'createRemoteAppComponent and obtain ref property' ,  async  ( )  =>  { 
@@ -97,10 +112,14 @@ describe('bridge', () => {
97112    ) ; 
98113    expect ( getHtml ( container ) ) . toMatch ( 'loading' ) ; 
99114
100-     await  sleep ( 200 ) ; 
101-     expect ( getHtml ( container ) ) . toMatch ( 'life cycle render' ) ; 
102-     expect ( getHtml ( container ) ) . toMatch ( 'hello world' ) ; 
103-     expect ( ref . current ) . not . toBeNull ( ) ; 
115+     await  waitFor ( 
116+       ( )  =>  { 
117+         expect ( getHtml ( container ) ) . toMatch ( 'life cycle render' ) ; 
118+         expect ( getHtml ( container ) ) . toMatch ( 'hello world' ) ; 
119+         expect ( ref . current ) . not . toBeNull ( ) ; 
120+       } , 
121+       {  timeout : 2000  } , 
122+     ) ; 
104123  } ) ; 
105124
106125  it ( 'createRemoteAppComponent with custom createRoot prop' ,  async  ( )  =>  { 
@@ -131,7 +150,11 @@ describe('bridge', () => {
131150    const  {  container }  =  render ( < RemoteComponent  /> ) ; 
132151    expect ( getHtml ( container ) ) . toMatch ( 'loading' ) ; 
133152
134-     await  sleep ( 200 ) ; 
135-     expect ( renderMock ) . toHaveBeenCalledTimes ( 1 ) ; 
153+     await  waitFor ( 
154+       ( )  =>  { 
155+         expect ( renderMock ) . toHaveBeenCalledTimes ( 1 ) ; 
156+       } , 
157+       {  timeout : 2000  } , 
158+     ) ; 
136159  } ) ; 
137160} ) ; 
0 commit comments