@@ -26,19 +26,15 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
26
26
// TODO: move these tests to the test file for `ReactNativeElement` when the legacy implementation is removed.
27
27
describe ( `ReactFabricPublicInstance (${ isModern ? 'modern' : 'legacy' } )` , ( ) => {
28
28
it ( 'should provide instances of the right class as refs in host components' , ( ) => {
29
- let node ;
29
+ const nodeRef = React . createRef < HostInstance > ( ) ;
30
30
31
31
const root = Fantom . createRoot ( ) ;
32
32
Fantom . runTask ( ( ) => {
33
- root . render (
34
- < View
35
- ref = { receivedNode => {
36
- node = receivedNode ;
37
- } }
38
- /> ,
39
- ) ;
33
+ root . render ( < View ref = { nodeRef } /> ) ;
40
34
} ) ;
41
35
36
+ const node = nullthrows ( nodeRef . current ) ;
37
+
42
38
expect ( node ) . toBeInstanceOf (
43
39
isModern ? ReactNativeElement : ReactFabricHostComponent ,
44
40
) ;
@@ -47,20 +43,13 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
47
43
describe ( 'blur' , ( ) => {
48
44
test ( 'blur() invokes TextInputState' , ( ) => {
49
45
const root = Fantom . createRoot ( ) ;
50
-
51
- let maybeNode ;
46
+ const nodeRef = React . createRef < HostInstance > ( ) ;
52
47
53
48
Fantom . runTask ( ( ) => {
54
- root . render (
55
- < View
56
- ref = { node => {
57
- maybeNode = node ;
58
- } }
59
- /> ,
60
- ) ;
49
+ root . render ( < View ref = { nodeRef } /> ) ;
61
50
} ) ;
62
51
63
- const node = nullthrows ( maybeNode ) ;
52
+ const node = nullthrows ( nodeRef . current ) ;
64
53
65
54
const blurTextInput = jest . fn ( ) ;
66
55
@@ -79,20 +68,13 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
79
68
describe ( 'focus' , ( ) => {
80
69
test ( 'focus() invokes TextInputState' , ( ) => {
81
70
const root = Fantom . createRoot ( ) ;
82
-
83
- let maybeNode ;
71
+ const ref = React . createRef < HostInstance > ( ) ;
84
72
85
73
Fantom . runTask ( ( ) => {
86
- root . render (
87
- < View
88
- ref = { node => {
89
- maybeNode = node ;
90
- } }
91
- /> ,
92
- ) ;
74
+ root . render ( < View ref = { ref } /> ) ;
93
75
} ) ;
94
76
95
- const node = nullthrows ( maybeNode ) ;
77
+ const node = nullthrows ( ref . current ) ;
96
78
97
79
const focusTextInput = jest . fn ( ) ;
98
80
@@ -111,21 +93,18 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
111
93
describe ( 'measure' , ( ) => {
112
94
it ( 'component.measure(...) invokes callback' , ( ) => {
113
95
const root = Fantom . createRoot ( ) ;
114
-
115
- let maybeNode ;
96
+ const ref = React . createRef < HostInstance > ( ) ;
116
97
117
98
Fantom . runTask ( ( ) => {
118
99
root . render (
119
100
< View
120
101
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
121
- ref = { node => {
122
- maybeNode = node ;
123
- } }
102
+ ref = { ref }
124
103
/> ,
125
104
) ;
126
105
} ) ;
127
106
128
- const node = nullthrows ( maybeNode ) ;
107
+ const node = nullthrows ( ref . current ) ;
129
108
130
109
const callback = jest . fn ( ) ;
131
110
node . measure ( callback ) ;
@@ -136,21 +115,18 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
136
115
137
116
it ( 'unmounted.measure(...) does nothing' , ( ) => {
138
117
const root = Fantom . createRoot ( ) ;
139
-
140
- let maybeNode ;
118
+ const ref = React . createRef < HostInstance > ( ) ;
141
119
142
120
Fantom . runTask ( ( ) => {
143
121
root . render (
144
122
< View
145
123
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
146
- ref = { node => {
147
- maybeNode = node ;
148
- } }
124
+ ref = { ref }
149
125
/> ,
150
126
) ;
151
127
} ) ;
152
128
153
- const node = nullthrows ( maybeNode ) ;
129
+ const node = nullthrows ( ref . current ) ;
154
130
155
131
Fantom . runTask ( ( ) => {
156
132
root . render ( < > </ > ) ;
@@ -166,21 +142,18 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
166
142
describe ( 'measureInWindow' , ( ) => {
167
143
it ( 'component.measureInWindow(...) invokes callback' , ( ) => {
168
144
const root = Fantom . createRoot ( ) ;
169
-
170
- let maybeNode ;
145
+ const ref = React . createRef < HostInstance > ( ) ;
171
146
172
147
Fantom . runTask ( ( ) => {
173
148
root . render (
174
149
< View
175
150
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
176
- ref = { node => {
177
- maybeNode = node ;
178
- } }
151
+ ref = { ref }
179
152
/> ,
180
153
) ;
181
154
} ) ;
182
155
183
- const node = nullthrows ( maybeNode ) ;
156
+ const node = nullthrows ( ref . current ) ;
184
157
185
158
const callback = jest . fn ( ) ;
186
159
node . measureInWindow ( callback ) ;
@@ -191,21 +164,18 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
191
164
192
165
it ( 'unmounted.measureInWindow(...) does nothing' , ( ) => {
193
166
const root = Fantom . createRoot ( ) ;
194
-
195
- let maybeNode ;
167
+ const ref = React . createRef < HostInstance > ( ) ;
196
168
197
169
Fantom . runTask ( ( ) => {
198
170
root . render (
199
171
< View
200
172
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
201
- ref = { node => {
202
- maybeNode = node ;
203
- } }
173
+ ref = { ref }
204
174
/> ,
205
175
) ;
206
176
} ) ;
207
177
208
- const node = nullthrows ( maybeNode ) ;
178
+ const node = nullthrows ( ref . current ) ;
209
179
210
180
Fantom . runTask ( ( ) => {
211
181
root . render ( < > </ > ) ;
@@ -221,29 +191,24 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
221
191
describe ( 'measureLayout' , ( ) => {
222
192
it ( 'component.measureLayout(component, ...) invokes callback' , ( ) => {
223
193
const root = Fantom . createRoot ( ) ;
224
-
225
- let maybeParentNode ;
226
- let maybeChildNode ;
194
+ const parentRef = React . createRef < HostInstance > ( ) ;
195
+ const childRef = React . createRef < HostInstance > ( ) ;
227
196
228
197
Fantom . runTask ( ( ) => {
229
198
root . render (
230
199
< View
231
200
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
232
- ref = { node => {
233
- maybeParentNode = node ;
234
- } } >
201
+ ref = { parentRef } >
235
202
< View
236
203
style = { { width : 10 , height : 10 , left : 20 , top : 20 } }
237
- ref = { node => {
238
- maybeChildNode = node ;
239
- } }
204
+ ref = { childRef }
240
205
/>
241
206
</ View > ,
242
207
) ;
243
208
} ) ;
244
209
245
- const parentNode = nullthrows ( maybeParentNode ) ;
246
- const childNode = nullthrows ( maybeChildNode ) ;
210
+ const parentNode = nullthrows ( parentRef . current ) ;
211
+ const childNode = nullthrows ( childRef . current ) ;
247
212
248
213
const callback = jest . fn ( ) ;
249
214
childNode . measureLayout ( parentNode , callback ) ;
@@ -254,29 +219,24 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
254
219
255
220
it ( 'unmounted.measureLayout(component, ...) does nothing' , ( ) => {
256
221
const root = Fantom . createRoot ( ) ;
257
-
258
- let maybeParentNode ;
259
- let maybeChildNode ;
222
+ const parentRef = React . createRef < HostInstance > ( ) ;
223
+ const childRef = React . createRef < HostInstance > ( ) ;
260
224
261
225
Fantom . runTask ( ( ) => {
262
226
root . render (
263
227
< View
264
228
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
265
- ref = { node => {
266
- maybeParentNode = node ;
267
- } } >
229
+ ref = { parentRef } >
268
230
< View
269
231
style = { { width : 10 , height : 10 , left : 20 , top : 20 } }
270
- ref = { node => {
271
- maybeChildNode = node ;
272
- } }
232
+ ref = { childRef }
273
233
/>
274
234
</ View > ,
275
235
) ;
276
236
} ) ;
277
237
278
- const parentNode = nullthrows ( maybeParentNode ) ;
279
- const childNode = nullthrows ( maybeChildNode ) ;
238
+ const parentNode = nullthrows ( parentRef . current ) ;
239
+ const childNode = nullthrows ( childRef . current ) ;
280
240
281
241
Fantom . runTask ( ( ) => {
282
242
root . render (
@@ -292,29 +252,24 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
292
252
293
253
it ( 'component.measureLayout(unmounted, ...) does nothing' , ( ) => {
294
254
const root = Fantom . createRoot ( ) ;
295
-
296
- let maybeParentNode ;
297
- let maybeChildNode ;
255
+ const parentRef = React . createRef < HostInstance > ( ) ;
256
+ const childRef = React . createRef < HostInstance > ( ) ;
298
257
299
258
Fantom . runTask ( ( ) => {
300
259
root . render (
301
260
< View
302
261
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
303
- ref = { node => {
304
- maybeParentNode = node ;
305
- } } >
262
+ ref = { parentRef } >
306
263
< View
307
264
style = { { width : 10 , height : 10 , left : 20 , top : 20 } }
308
- ref = { node => {
309
- maybeChildNode = node ;
310
- } }
265
+ ref = { childRef }
311
266
/>
312
267
</ View > ,
313
268
) ;
314
269
} ) ;
315
270
316
- const parentNode = nullthrows ( maybeParentNode ) ;
317
- const childNode = nullthrows ( maybeChildNode ) ;
271
+ const parentNode = nullthrows ( parentRef . current ) ;
272
+ const childNode = nullthrows ( childRef . current ) ;
318
273
319
274
Fantom . runTask ( ( ) => {
320
275
root . render (
@@ -330,29 +285,24 @@ export default function setUpTests({isModern}: {isModern: boolean}) {
330
285
331
286
it ( 'unmounted.measureLayout(unmounted, ...) does nothing' , ( ) => {
332
287
const root = Fantom . createRoot ( ) ;
333
-
334
- let maybeParentNode ;
335
- let maybeChildNode ;
288
+ const parentRef = React . createRef < HostInstance > ( ) ;
289
+ const childRef = React . createRef < HostInstance > ( ) ;
336
290
337
291
Fantom . runTask ( ( ) => {
338
292
root . render (
339
293
< View
340
294
style = { { width : 100 , height : 100 , left : 10 , top : 10 } }
341
- ref = { node => {
342
- maybeParentNode = node ;
343
- } } >
295
+ ref = { parentRef } >
344
296
< View
345
297
style = { { width : 10 , height : 10 , left : 20 , top : 20 } }
346
- ref = { node => {
347
- maybeChildNode = node ;
348
- } }
298
+ ref = { childRef }
349
299
/>
350
300
</ View > ,
351
301
) ;
352
302
} ) ;
353
303
354
- const parentNode = nullthrows ( maybeParentNode ) ;
355
- const childNode = nullthrows ( maybeChildNode ) ;
304
+ const parentNode = nullthrows ( parentRef . current ) ;
305
+ const childNode = nullthrows ( childRef . current ) ;
356
306
357
307
Fantom . runTask ( ( ) => {
358
308
root . render ( < > </ > ) ;
0 commit comments