7
7
screen ,
8
8
waitFor ,
9
9
} from '@testing-library/react' ;
10
- import { createContainer , getHtml , sleep } from './util' ;
10
+ import { createContainer , getHtml } from './util' ;
11
11
12
12
describe ( 'bridge' , ( ) => {
13
13
let containerInfo : ReturnType < typeof createContainer > ;
@@ -31,17 +31,28 @@ describe('bridge', () => {
31
31
dom : containerInfo ?. container ,
32
32
} ) ;
33
33
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 } ,
37
41
) ;
38
42
39
43
lifeCycle . destroy ( {
40
44
dom : containerInfo ?. container ,
41
45
moduleName : 'test' ,
42
46
} ) ;
43
47
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
+ ) ;
45
56
} ) ;
46
57
47
58
it ( 'createRemoteAppComponent' , async ( ) => {
@@ -66,9 +77,13 @@ describe('bridge', () => {
66
77
) ;
67
78
expect ( getHtml ( container ) ) . toMatch ( 'loading' ) ;
68
79
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
+ ) ;
72
87
} ) ;
73
88
74
89
it ( 'createRemoteAppComponent and obtain ref property' , async ( ) => {
@@ -97,10 +112,14 @@ describe('bridge', () => {
97
112
) ;
98
113
expect ( getHtml ( container ) ) . toMatch ( 'loading' ) ;
99
114
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
+ ) ;
104
123
} ) ;
105
124
106
125
it ( 'createRemoteAppComponent with custom createRoot prop' , async ( ) => {
@@ -131,7 +150,11 @@ describe('bridge', () => {
131
150
const { container } = render ( < RemoteComponent /> ) ;
132
151
expect ( getHtml ( container ) ) . toMatch ( 'loading' ) ;
133
152
134
- await sleep ( 200 ) ;
135
- expect ( renderMock ) . toHaveBeenCalledTimes ( 1 ) ;
153
+ await waitFor (
154
+ ( ) => {
155
+ expect ( renderMock ) . toHaveBeenCalledTimes ( 1 ) ;
156
+ } ,
157
+ { timeout : 2000 } ,
158
+ ) ;
136
159
} ) ;
137
160
} ) ;
0 commit comments