Commit 5e64e90
Remove ReactNativeElement from Fantom tests (nullthrows/HostInstance/HTMLElement) (#57468)
Summary:
Pull Request resolved: #57468
Removes the `ensureInstance(ref.current, ReactNativeElement)` pattern from Fantom tests. Host refs are typed as `HostInstance` and read with `nullthrows(ref.current)`; component-specific instance types (e.g. `React.ElementRef<typeof TextInput>`, `React.ElementRef<typeof ScrollView>`) are kept only where a test actually uses a component's imperative API (`focus`/`blur`/`clear`, `getInnerViewRef`, etc.). This drops the `ReactNativeElement`/`ensureInstance` imports from tests that only needed a non-null host instance.
Where a test genuinely needs a runtime type check, `instanceof ReactNativeElement` / `toBeInstanceOf(ReactNativeElement)` is replaced with the standard `instanceof HTMLElement` (a global), since React Native elements are instances of `HTMLElement` at runtime.
This also covers the internal `-itest.fb.js` tests and the shared ShadowNode test utilities (`ShadowNodeReferenceCounter`/`ShadowNodeRevisionGetter`), which now type their refs as `HostInstance`.
Known follow-up: the RN Flow global type definitions still need to be fixed. At the type level `HTMLElement` does not match `HostInstance` yet, even though the runtime values do. Because of this, `HTMLElement` cannot be used where a narrowed value flows into RN-internal APIs typed as `HostInstance`/`ReadOnlyNode` (e.g. `VirtualView`, which instead types its helper params as `HostInstance` directly and passes them through without a narrowing check). Aligning the `HTMLElement` global definition with `HostInstance` would let those remaining spots use `HTMLElement` too.
This is a test-only change with no runtime or user-facing impact.
Changelog:
[Internal]
Reviewed By: christophpurrer
Differential Revision: D110888634
fbshipit-source-id: c570700ed82fd8333093ee01816e872c486f3e8f1 parent b67b7ba commit 5e64e90
30 files changed
Lines changed: 166 additions & 264 deletions
File tree
- packages/react-native
- Libraries
- Animated/__tests__
- Components
- ActivityIndicator/__tests__
- Pressable/__tests__
- ScrollView/__tests__
- Switch/__tests__
- Touchable/__tests__
- View/__tests__
- Image/__tests__
- Modal/__tests__
- Pressability/__tests__
- ReactNative/__tests__
- Utilities/__tests__
- src/private
- __tests__/utilities
- __tests__
- components/virtualview/__tests__
- renderer
- branching/__tests__
- consistency/__tests__
- mounting/__tests__
- webapis
- dom/nodes/__tests__
- intersectionobserver/__tests__
- structuredClone/__tests__
Lines changed: 18 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
| 329 | + | |
| 330 | + | |
334 | 331 | | |
335 | 332 | | |
336 | 333 | | |
| |||
397 | 394 | | |
398 | 395 | | |
399 | 396 | | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
| 397 | + | |
404 | 398 | | |
405 | 399 | | |
406 | 400 | | |
| |||
438 | 432 | | |
439 | 433 | | |
440 | 434 | | |
441 | | - | |
| 435 | + | |
442 | 436 | | |
443 | 437 | | |
444 | 438 | | |
| |||
492 | 486 | | |
493 | 487 | | |
494 | 488 | | |
495 | | - | |
| 489 | + | |
496 | 490 | | |
497 | 491 | | |
498 | 492 | | |
| |||
592 | 586 | | |
593 | 587 | | |
594 | 588 | | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
| 589 | + | |
| 590 | + | |
600 | 591 | | |
601 | 592 | | |
602 | 593 | | |
| |||
676 | 667 | | |
677 | 668 | | |
678 | 669 | | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
| 670 | + | |
| 671 | + | |
684 | 672 | | |
685 | 673 | | |
686 | 674 | | |
| |||
751 | 739 | | |
752 | 740 | | |
753 | 741 | | |
754 | | - | |
| 742 | + | |
755 | 743 | | |
756 | 744 | | |
757 | 745 | | |
| |||
819 | 807 | | |
820 | 808 | | |
821 | 809 | | |
822 | | - | |
| 810 | + | |
823 | 811 | | |
824 | 812 | | |
825 | 813 | | |
| |||
891 | 879 | | |
892 | 880 | | |
893 | 881 | | |
894 | | - | |
| 882 | + | |
895 | 883 | | |
896 | 884 | | |
897 | 885 | | |
| |||
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
108 | 107 | | |
109 | 108 | | |
110 | 109 | | |
111 | | - | |
| 110 | + | |
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
| |||
414 | 413 | | |
415 | 414 | | |
416 | 415 | | |
417 | | - | |
| 416 | + | |
418 | 417 | | |
419 | 418 | | |
420 | 419 | | |
| |||
Lines changed: 8 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | | - | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
170 | | - | |
171 | | - | |
172 | | - | |
| 171 | + | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
| 183 | + | |
185 | 184 | | |
186 | 185 | | |
187 | 186 | | |
188 | 187 | | |
189 | 188 | | |
190 | 189 | | |
191 | | - | |
| 190 | + | |
192 | 191 | | |
193 | 192 | | |
194 | 193 | | |
| |||
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | | - | |
23 | | - | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
| 266 | + | |
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
| 305 | + | |
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| |||
Lines changed: 4 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
96 | | - | |
| 94 | + | |
97 | 95 | | |
98 | 96 | | |
99 | 97 | | |
| |||
111 | 109 | | |
112 | 110 | | |
113 | 111 | | |
114 | | - | |
| 112 | + | |
115 | 113 | | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | | - | |
| 119 | + | |
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
| |||
131 | 129 | | |
132 | 130 | | |
133 | 131 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 132 | + | |
138 | 133 | | |
139 | 134 | | |
140 | 135 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | | - | |
19 | | - | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
0 commit comments