Use public APIs in Fantom tests (#58567)

Summary:
Pull Request resolved: https://github.com/react/react-native/pull/58567

Replace eligible React Native deep imports in Fantom tests with package exports, Fantom APIs, DOM globals, and types derived from exported symbols. Keep implementation-specific imports where the public surface does not expose equivalent behavior or compatible Flow types.

Changelog: [Internal]

___

Reviewed By: cipolleschi

Differential Revision: D120517166

fbshipit-source-id: 6ba6ec2c6159cca6309f558ccf478c49220e85fc
This commit is contained in:
Rubén Norte authored and meta-codesync[bot] committed 2026-09-18 07:27:28 -07:00
1 parent 15d3bcad5a
commit 7a6314090d
18 files changed
+405 -510

No files matched your search

@@ -11,12 +11,12 @@
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
import * as Fantom from '@react-native/fantom';
import * as React from 'react';
import {View} from 'react-native';
type ViewStyleProp = NonNullable<React.PropOf<View, 'style'>>;
// These tests render <View> with string-valued CSS properties. With
// `enableNativeCSSParsing` forced on, the strings are parsed by the C++ CSS
// parsers (color functions, transforms, filters, box shadows, gradients), and
@@ -9,7 +9,7 @@
*/
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import type {FlatListProps} from 'react-native/Libraries/Lists/FlatList';
import type {FlatListProps} from 'react-native';
import * as Fantom from '@react-native/fantom';
import nullthrows from 'nullthrows';
@@ -10,7 +10,7 @@
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import type {SectionBase} from 'react-native/Libraries/Lists/SectionList';
import type {SectionBase} from 'react-native';
import * as Fantom from '@react-native/fantom';
import nullthrows from 'nullthrows';
@@ -17,7 +17,6 @@ import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef, startTransition, useDeferredValue, useState} from 'react';
import {View} from 'react-native';
import {NativeEventCategory} from 'react-native/src/private/testing/fantom/specs/NativeFantom';
describe('stale event handlers from interrupted render', () => {
// This test demonstrates a bug where canonical.currentProps (which stores
@@ -80,7 +79,7 @@ describe('stale event handlers from interrupted render', () => {
'onPointerUp',
{x: 0, y: 0},
{
category: NativeEventCategory.Discrete,
category: Fantom.NativeEventCategory.Discrete,
},
);
}
@@ -23,8 +23,6 @@ import accessibilityPropsSuite, {
rolePropSuite,
} from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite';
import {testIDPropSuite} from 'react-native/src/private/__tests__/utilities/commonPropsSuite';
import ReadOnlyElement from 'react-native/src/private/webapis/dom/nodes/ReadOnlyElement';
import ReadOnlyText from 'react-native/src/private/webapis/dom/nodes/ReadOnlyText';
const TEST_TEXT = 'the text';
@@ -661,7 +659,7 @@ describe('<Text>', () => {
const element = nullthrows(elementRef.current);
expect(element.childNodes.length).toBe(1);
const textChild = ensureInstance(element.childNodes[0], ReadOnlyText);
const textChild = ensureInstance(element.childNodes[0], globalThis.Text);
expect(textChild.textContent).toBe(TEST_TEXT);
});
@@ -681,19 +679,16 @@ describe('<Text>', () => {
const element = nullthrows(elementRef.current);
expect(element.childNodes.length).toBe(2);
const firstChild = ensureInstance(element.childNodes[0], ReadOnlyText);
const firstChild = ensureInstance(element.childNodes[0], globalThis.Text);
expect(firstChild.textContent).toBe('Some text ');
const secondChild = ensureInstance(
element.childNodes[1],
ReadOnlyElement,
);
const secondChild = ensureInstance(element.childNodes[1], Element);
expect(secondChild.tagName).toBe('RN:Text');
expect(secondChild.childNodes.length).toBe(1);
const secondChildText = ensureInstance(
secondChild.childNodes[0],
ReadOnlyText,
globalThis.Text,
);
expect(secondChildText.textContent).toBe('also in bold');
});
@@ -10,12 +10,12 @@
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import type {HardwareBackPressEvent} from 'react-native/Libraries/Utilities/BackHandler';
import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';
import BackHandler from 'react-native/Libraries/Utilities/BackHandler';
import {BackHandler, DeviceEventEmitter} from 'react-native';
import {HardwareBackPressEvent as HardwareBackPressEventClass} from 'react-native/Libraries/Utilities/HardwareBackPressEvent';
type BackPressHandler = Parameters<typeof BackHandler.addEventListener>[1];
type HardwareBackPressEvent = Parameters<BackPressHandler>[0];
describe('BackHandler', () => {
const subscriptions: Array<{remove: () => void, ...}> = [];
@@ -44,7 +44,7 @@ describe('BackHandler', () => {
BackHandler.addEventListener('hardwareBackPress', handler2),
);
RCTDeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 100});
DeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 100});
expect(callOrder).toEqual(['second']);
});
@@ -67,7 +67,7 @@ describe('BackHandler', () => {
BackHandler.addEventListener('hardwareBackPress', handler2),
);
RCTDeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 100});
DeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 100});
expect(callOrder).toEqual(['second', 'first']);
});
@@ -83,7 +83,7 @@ describe('BackHandler', () => {
BackHandler.addEventListener('hardwareBackPress', handler),
);
RCTDeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 42});
DeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 42});
expect(receivedEvent).toBeInstanceOf(HardwareBackPressEventClass);
});
@@ -99,7 +99,7 @@ describe('BackHandler', () => {
BackHandler.addEventListener('hardwareBackPress', handler),
);
RCTDeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 42});
DeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 42});
expect(receivedEvent?.timeStamp).toBe(42);
});
@@ -116,7 +116,7 @@ describe('BackHandler', () => {
);
const before = performance.now();
RCTDeviceEventEmitter.emit('hardwareBackPress', null);
DeviceEventEmitter.emit('hardwareBackPress', null);
const after = performance.now();
const timeStamp = receivedEvent?.timeStamp;
@@ -137,7 +137,7 @@ describe('BackHandler', () => {
const sub = BackHandler.addEventListener('hardwareBackPress', handler);
sub.remove();
RCTDeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 100});
DeviceEventEmitter.emit('hardwareBackPress', {timeStamp: 100});
expect(called).toBe(false);
});
@@ -11,7 +11,6 @@
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import {HardwareBackPressEvent} from 'react-native/Libraries/Utilities/HardwareBackPressEvent';
import Event from 'react-native/src/private/webapis/dom/events/Event';
import {setEventInitTimeStamp} from 'react-native/src/private/webapis/dom/events/internals/EventInternals';
describe('HardwareBackPressEvent', () => {
@@ -12,11 +12,7 @@
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import type {
NativePointerEvent,
PointerEvent,
} from 'react-native/Libraries/Types/CoreEventTypes';
import type {ReadOnlyNodeWithEventTarget} from 'react-native/src/private/webapis/dom/nodes/ReadOnlyNode';
import type {NativePointerEvent, PointerEvent} from 'react-native';
import * as Fantom from '@react-native/fantom';
import * as React from 'react';
@@ -25,7 +21,7 @@ import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/
import Event from 'react-native/src/private/webapis/dom/events/Event';
// Temporary cast until ReadOnlyNode extends EventTarget ungated.
function asEventTarget(node: ?interface {}): ReadOnlyNodeWithEventTarget {
function asEventTarget(node: ?interface {}): EventTarget {
if (node == null) {
throw new Error('Expected non-null node');
}
@@ -10,15 +10,13 @@
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import CustomEvent from 'react-native/src/private/webapis/dom/events/CustomEvent';
import Event from 'react-native/src/private/webapis/dom/events/Event';
describe('CustomEvent', () => {
it('extends Event', () => {
const event = new CustomEvent('foo', {
bubbles: true,
cancelable: true,
composed: true,
detail: null,
});
expect(event.type).toBe('foo');
@@ -21,7 +21,6 @@ import {createRef} from 'react';
import {View} from 'react-native';
import ReactNativeDocument from 'react-native/src/private/webapis/dom/nodes/ReactNativeDocument';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
import ReadOnlyNode from 'react-native/src/private/webapis/dom/nodes/ReadOnlyNode';
describe('ReactNativeDocument', () => {
it('is connected until the surface is destroyed', () => {
@@ -99,7 +98,7 @@ describe('ReactNativeDocument', () => {
const document = ensureInstance(element.ownerDocument, ReactNativeDocument);
expect(document.nodeName).toBe('#document');
expect(document.nodeType).toBe(ReadOnlyNode.DOCUMENT_NODE);
expect(document.nodeType).toBe(Node.DOCUMENT_NODE);
expect(document.nodeValue).toBe(null);
expect(document.textContent).toBe(null);
});
@@ -155,28 +154,22 @@ describe('ReactNativeDocument', () => {
).toBe(0);
expect(document.compareDocumentPosition(documentElement)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY |
ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING,
Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING,
);
expect(document.compareDocumentPosition(element)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY |
ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING,
Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING,
);
expect(documentElement.compareDocumentPosition(document)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINS |
ReadOnlyNode.DOCUMENT_POSITION_PRECEDING,
Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING,
);
expect(documentElement.compareDocumentPosition(element)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY |
ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING,
Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING,
);
expect(element.compareDocumentPosition(document)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINS |
ReadOnlyNode.DOCUMENT_POSITION_PRECEDING,
Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING,
);
expect(element.compareDocumentPosition(documentElement)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINS |
ReadOnlyNode.DOCUMENT_POSITION_PRECEDING,
Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING,
);
});
@@ -18,25 +18,19 @@ import type {HostInstance} from 'react-native';
import ensureInstance from '../../../../__tests__/utilities/ensureInstance';
import TextInputState from '../../../../../../Libraries/Components/TextInput/TextInputState';
import * as Fantom from '@react-native/fantom';
import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef} from 'react';
import {Modal, ScrollView, Text, TextInput, View} from 'react-native';
import {
NativeText,
NativeVirtualText,
} from 'react-native/Libraries/Text/TextNativeComponent';
Modal,
ScrollView,
Text,
TextInput,
View,
unstable_NativeText as NativeText,
} from 'react-native';
import {NativeVirtualText} from 'react-native/Libraries/Text/TextNativeComponent';
import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags';
import Event from 'react-native/src/private/webapis/dom/events/Event';
import ReactNativeDocument from 'react-native/src/private/webapis/dom/nodes/ReactNativeDocument';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
import ReadOnlyElement from 'react-native/src/private/webapis/dom/nodes/ReadOnlyElement';
import ReadOnlyNode from 'react-native/src/private/webapis/dom/nodes/ReadOnlyNode';
import HTMLCollection from 'react-native/src/private/webapis/dom/oldstylecollections/HTMLCollection';
import NodeList from 'react-native/src/private/webapis/dom/oldstylecollections/NodeList';
function ensureReactNativeElement(value: unknown): ReactNativeElement {
return ensureInstance(value, ReactNativeElement);
}
// The public imperative EventTarget API is not part of the static type of this
// final class (it is only present at runtime, gated by feature flags), so we
@@ -63,7 +57,7 @@ describe('ReactNativeElement', () => {
root.render(<View ref={ref} />);
});
expect(ref.current).toBeInstanceOf(ReactNativeElement);
expect(ref.current).toBeInstanceOf(HTMLElement);
});
describe('extends `ReadOnlyNode`', () => {
@@ -75,7 +69,7 @@ describe('ReactNativeElement', () => {
root.render(<View ref={ref} />);
});
expect(ref.current).toBeInstanceOf(ReadOnlyNode);
expect(ref.current).toBeInstanceOf(Node);
});
describe('nodeType', () => {
@@ -97,15 +91,15 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNodeA = ensureReactNativeElement(childNodeARef.current);
const childNodeB = ensureReactNativeElement(childNodeBRef.current);
const childNodeC = ensureReactNativeElement(childNodeCRef.current);
const parentNode = nullthrows(parentRef.current);
const childNodeA = nullthrows(childNodeARef.current);
const childNodeB = nullthrows(childNodeBRef.current);
const childNodeC = nullthrows(childNodeCRef.current);
expect(parentNode.nodeType).toBe(ReadOnlyNode.ELEMENT_NODE);
expect(childNodeA.nodeType).toBe(ReadOnlyNode.ELEMENT_NODE);
expect(childNodeB.nodeType).toBe(ReadOnlyNode.ELEMENT_NODE);
expect(childNodeC.nodeType).toBe(ReadOnlyNode.ELEMENT_NODE);
expect(parentNode.nodeType).toBe(Node.ELEMENT_NODE);
expect(childNodeA.nodeType).toBe(Node.ELEMENT_NODE);
expect(childNodeB.nodeType).toBe(Node.ELEMENT_NODE);
expect(childNodeC.nodeType).toBe(Node.ELEMENT_NODE);
});
});
@@ -128,10 +122,10 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNodeA = ensureReactNativeElement(childNodeARef.current);
const childNodeB = ensureReactNativeElement(childNodeBRef.current);
const childNodeC = ensureReactNativeElement(childNodeCRef.current);
const parentNode = nullthrows(parentRef.current);
const childNodeA = nullthrows(childNodeARef.current);
const childNodeB = nullthrows(childNodeBRef.current);
const childNodeC = nullthrows(childNodeCRef.current);
expect(parentNode.nodeValue).toBe(null);
expect(childNodeA.nodeValue).toBe(null);
@@ -159,10 +153,10 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNodeA = ensureReactNativeElement(childNodeARef.current);
const childNodeB = ensureReactNativeElement(childNodeBRef.current);
const childNodeC = ensureReactNativeElement(childNodeCRef.current);
const parentNode = nullthrows(parentRef.current);
const childNodeA = nullthrows(childNodeARef.current);
const childNodeB = nullthrows(childNodeBRef.current);
const childNodeC = nullthrows(childNodeCRef.current);
const childNodes = parentNode.childNodes;
expect(childNodes).toBeInstanceOf(NodeList);
@@ -226,21 +220,19 @@ describe('ReactNativeElement', () => {
);
});
const parentANode = ensureReactNativeElement(parentANodeRef.current);
const childANode = ensureReactNativeElement(childANodeRef.current);
const parentBNode = ensureReactNativeElement(parentBNodeRef.current);
const childBNode = ensureReactNativeElement(childBNodeRef.current);
const parentANode = nullthrows(parentANodeRef.current);
const childANode = nullthrows(childANodeRef.current);
const parentBNode = nullthrows(parentBNodeRef.current);
const childBNode = nullthrows(childBNodeRef.current);
expect(childANode.getRootNode()).toBe(childBNode.getRootNode());
const document = childANode.getRootNode();
expect(document.childNodes.length).toBe(1);
expect(document.childNodes[0]).toBeInstanceOf(ReactNativeElement);
expect(document.childNodes[0]).toBeInstanceOf(HTMLElement);
const documentElement = document.childNodes[0];
expect(documentElement.childNodes[0]).toBeInstanceOf(
ReactNativeElement,
);
expect(documentElement.childNodes[0]).toBeInstanceOf(HTMLElement);
expect(documentElement.childNodes[0]).toBe(parentANode);
expect(documentElement.childNodes[1]).toBe(parentBNode);
@@ -282,10 +274,10 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNodeA = ensureReactNativeElement(childNodeARef.current);
const childNodeB = ensureReactNativeElement(childNodeBRef.current);
const childNodeC = ensureReactNativeElement(childNodeCRef.current);
const parentNode = nullthrows(parentRef.current);
const childNodeA = nullthrows(childNodeARef.current);
const childNodeB = nullthrows(childNodeBRef.current);
const childNodeC = nullthrows(childNodeCRef.current);
expect(parentNode.isConnected).toBe(true);
expect(parentNode.firstChild).toBe(childNodeA);
@@ -413,12 +405,9 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const modalNode = ensureReactNativeElement(modalRef.current);
const document = ensureInstance(
parentNode.ownerDocument,
ReactNativeDocument,
);
const parentNode = nullthrows(parentRef.current);
const modalNode = nullthrows(modalRef.current);
const document = ensureInstance(parentNode.ownerDocument, Document);
// Capture the relations before tearing down, so cleanup runs even if
// the assertions below fail.
@@ -465,57 +454,55 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNodeA = ensureReactNativeElement(childNodeARef.current);
const childNodeAA = ensureReactNativeElement(childNodeAARef.current);
const childNodeB = ensureReactNativeElement(childNodeBRef.current);
const childNodeBB = ensureReactNativeElement(childNodeBBRef.current);
const parentNode = nullthrows(parentRef.current);
const childNodeA = nullthrows(childNodeARef.current);
const childNodeAA = nullthrows(childNodeAARef.current);
const childNodeB = nullthrows(childNodeBRef.current);
const childNodeBB = nullthrows(childNodeBBRef.current);
// Node/self
expect(parentNode.compareDocumentPosition(parentNode)).toBe(0);
expect(parentNode.contains(parentNode)).toBe(true);
// Parent/child
expect(parentNode.compareDocumentPosition(childNodeA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY |
ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING,
Node.DOCUMENT_POSITION_CONTAINED_BY |
Node.DOCUMENT_POSITION_FOLLOWING,
);
expect(parentNode.contains(childNodeA)).toBe(true);
// Child/parent
expect(childNodeA.compareDocumentPosition(parentNode)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINS |
ReadOnlyNode.DOCUMENT_POSITION_PRECEDING,
Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING,
);
expect(childNodeA.contains(parentNode)).toBe(false);
// Grandparent/grandchild
expect(parentNode.compareDocumentPosition(childNodeAA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY |
ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING,
Node.DOCUMENT_POSITION_CONTAINED_BY |
Node.DOCUMENT_POSITION_FOLLOWING,
);
expect(parentNode.contains(childNodeAA)).toBe(true);
// Grandchild/grandparent
expect(childNodeAA.compareDocumentPosition(parentNode)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_CONTAINS |
ReadOnlyNode.DOCUMENT_POSITION_PRECEDING,
Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING,
);
expect(childNodeAA.contains(parentNode)).toBe(false);
// Sibling/sibling
expect(childNodeA.compareDocumentPosition(childNodeB)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING,
Node.DOCUMENT_POSITION_FOLLOWING,
);
expect(childNodeA.contains(childNodeB)).toBe(false);
// Sibling/sibling
expect(childNodeB.compareDocumentPosition(childNodeA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_PRECEDING,
Node.DOCUMENT_POSITION_PRECEDING,
);
expect(childNodeB.contains(childNodeA)).toBe(false);
// Cousing/cousing
expect(childNodeAA.compareDocumentPosition(childNodeBB)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING,
Node.DOCUMENT_POSITION_FOLLOWING,
);
expect(childNodeAA.contains(childNodeBB)).toBe(false);
// Cousing/cousing
expect(childNodeBB.compareDocumentPosition(childNodeAA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_PRECEDING,
Node.DOCUMENT_POSITION_PRECEDING,
);
expect(childNodeBB.contains(childNodeAA)).toBe(false);
@@ -531,22 +518,22 @@ describe('ReactNativeElement', () => {
// Node/disconnected
expect(parentNode.compareDocumentPosition(childNodeAA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(parentNode.contains(childNodeAA)).toBe(false);
// Disconnected/node
expect(childNodeAA.compareDocumentPosition(parentNode)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(childNodeAA.contains(parentNode)).toBe(false);
// Disconnected/disconnected
expect(childNodeAA.compareDocumentPosition(childNodeBB)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(childNodeAA.contains(childNodeBB)).toBe(false);
// Disconnected/disconnected
expect(childNodeBB.compareDocumentPosition(childNodeAA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(childNodeBB.contains(childNodeAA)).toBe(false);
// Disconnected/self
@@ -566,26 +553,24 @@ describe('ReactNativeElement', () => {
);
});
const altParentNode = ensureReactNativeElement(
altParentNodeRef.current,
);
const altParentNode = nullthrows(altParentNodeRef.current);
// Node/same position in different tree
expect(altParentNode.compareDocumentPosition(parentNode)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(parentNode.compareDocumentPosition(altParentNode)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(parentNode.contains(altParentNode)).toBe(false);
expect(altParentNode.contains(parentNode)).toBe(false);
// Node/child position in different tree
expect(altParentNode.compareDocumentPosition(childNodeA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(childNodeA.compareDocumentPosition(altParentNode)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(altParentNode.contains(childNodeA)).toBe(false);
expect(childNodeA.contains(altParentNode)).toBe(false);
@@ -599,10 +584,10 @@ describe('ReactNativeElement', () => {
expect(parentNode.contains(parentNode)).toBe(true);
expect(parentNode.compareDocumentPosition(childNodeA)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
expect(parentNode.compareDocumentPosition(altParentNode)).toBe(
ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED,
Node.DOCUMENT_POSITION_DISCONNECTED,
);
});
});
@@ -617,7 +602,7 @@ describe('ReactNativeElement', () => {
root.render(<View ref={ref} />);
});
expect(ref.current).toBeInstanceOf(ReadOnlyElement);
expect(ref.current).toBeInstanceOf(Element);
});
describe('children / childElementCount', () => {
@@ -639,16 +624,10 @@ describe('ReactNativeElement', () => {
);
});
const parentElement = ensureReactNativeElement(parentRef.current);
const childElementA = ensureReactNativeElement(
childElementARef.current,
);
const childElementB = ensureReactNativeElement(
childElementBRef.current,
);
const childElementC = ensureReactNativeElement(
childElementCRef.current,
);
const parentElement = nullthrows(parentRef.current);
const childElementA = nullthrows(childElementARef.current);
const childElementB = nullthrows(childElementBRef.current);
const childElementC = nullthrows(childElementCRef.current);
const children = parentElement.children;
expect(children).toBeInstanceOf(HTMLCollection);
@@ -709,16 +688,10 @@ describe('ReactNativeElement', () => {
);
});
const parentElement = ensureReactNativeElement(parentRef.current);
const childElementA = ensureReactNativeElement(
childElementARef.current,
);
const childElementB = ensureReactNativeElement(
childElementBRef.current,
);
const childElementC = ensureReactNativeElement(
childElementCRef.current,
);
const parentElement = nullthrows(parentRef.current);
const childElementA = nullthrows(childElementARef.current);
const childElementB = nullthrows(childElementBRef.current);
const childElementC = nullthrows(childElementCRef.current);
expect(parentElement.firstElementChild).toBe(childElementA);
expect(parentElement.lastElementChild).toBe(childElementC);
@@ -819,8 +792,8 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNodeA = ensureReactNativeElement(childNodeARef.current);
const parentNode = nullthrows(parentRef.current);
const childNodeA = nullthrows(childNodeARef.current);
expect(parentNode.textContent).toBe('Hello world!');
expect(childNodeA.textContent).toBe('world!');
@@ -845,7 +818,7 @@ describe('ReactNativeElement', () => {
);
});
const childNodeB = ensureReactNativeElement(childNodeBRef.current);
const childNodeB = nullthrows(childNodeBRef.current);
expect(parentNode.textContent).toBe('Hello world again and again!');
expect(childNodeA.textContent).toBe('world ');
@@ -875,7 +848,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
const boundingClientRect = element.getBoundingClientRect();
expect(boundingClientRect).toBeInstanceOf(DOMRect);
@@ -920,7 +893,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
const boundingClientRect = element.getBoundingClientRect();
expect(boundingClientRect).toBeInstanceOf(DOMRect);
@@ -955,7 +928,7 @@ describe('ReactNativeElement', () => {
);
});
const textElement = ensureReactNativeElement(textRef.current);
const textElement = nullthrows(textRef.current);
// Text element should have a valid bounding rect
const textBoundingRect = textElement.getBoundingClientRect();
@@ -1004,10 +977,8 @@ describe('ReactNativeElement', () => {
);
});
const outerTextElement = ensureReactNativeElement(outerTextRef.current);
const nestedTextElement = ensureReactNativeElement(
nestedTextRef.current,
);
const outerTextElement = nullthrows(outerTextRef.current);
const nestedTextElement = nullthrows(nestedTextRef.current);
// Outer text element should have a valid bounding rect
const outerTextBoundingRect = outerTextElement.getBoundingClientRect();
@@ -1063,7 +1034,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.scrollLeft).toBeCloseTo(5.1);
expect(element.scrollTop).toBeCloseTo(10.2);
@@ -1093,7 +1064,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.scrollWidth).toBe(200);
expect(element.scrollHeight).toBe(1500);
@@ -1125,7 +1096,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.clientWidth).toBe(200);
expect(element.clientHeight).toBe(250);
@@ -1157,7 +1128,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.clientLeft).toBe(200);
expect(element.clientTop).toBe(250);
@@ -1186,7 +1157,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.id).toBe('<react-native-element-id>');
});
@@ -1205,7 +1176,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.id).toBe('<react-native-element-id>');
});
@@ -1220,7 +1191,7 @@ describe('ReactNativeElement', () => {
root.render(<View ref={elementRef} />);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.tagName).toBe('RN:View');
});
@@ -1237,8 +1208,8 @@ describe('ReactNativeElement', () => {
root.render(<View ref={ref} />);
});
const node = ensureReactNativeElement(ref.current);
expect(node).toBeInstanceOf(ReactNativeElement);
const node = nullthrows(ref.current);
expect(node).toBeInstanceOf(HTMLElement);
});
describe('offsetWidth / offsetHeight', () => {
@@ -1262,7 +1233,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.offsetWidth).toBe(50);
expect(element.offsetHeight).toBe(100);
@@ -1295,8 +1266,8 @@ describe('ReactNativeElement', () => {
);
});
const parentElement = ensureReactNativeElement(parentRef.current);
const element = ensureReactNativeElement(elementRef.current);
const parentElement = nullthrows(parentRef.current);
const element = nullthrows(elementRef.current);
expect(element.offsetTop).toBe(11);
expect(element.offsetLeft).toBe(5);
@@ -1346,8 +1317,8 @@ describe('ReactNativeElement', () => {
);
});
const parentElement = ensureReactNativeElement(parentRef.current);
const element = ensureReactNativeElement(elementRef.current);
const parentElement = nullthrows(parentRef.current);
const element = nullthrows(elementRef.current);
expect(element.offsetTop).toBe(11);
expect(element.offsetLeft).toBe(5);
@@ -1374,7 +1345,7 @@ describe('ReactNativeElement', () => {
);
});
const element = ensureReactNativeElement(elementRef.current);
const element = nullthrows(elementRef.current);
expect(element.offsetTop).toBe(11);
expect(element.offsetLeft).toBe(5);
@@ -1392,7 +1363,7 @@ describe('ReactNativeElement', () => {
root.render(<TextInput ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const blurTextInput = jest.fn();
@@ -1417,7 +1388,7 @@ describe('ReactNativeElement', () => {
root.render(<TextInput ref={ref} />);
});
const node = ensureReactNativeElement(ref.current);
const node = nullthrows(ref.current);
const focusTextInput = jest.fn();
@@ -1447,7 +1418,7 @@ describe('ReactNativeElement', () => {
);
});
const node = ensureReactNativeElement(ref.current);
const node = nullthrows(ref.current);
const callback = jest.fn();
node.measure(callback);
@@ -1469,7 +1440,7 @@ describe('ReactNativeElement', () => {
);
});
const node = ensureReactNativeElement(ref.current);
const node = nullthrows(ref.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -1496,7 +1467,7 @@ describe('ReactNativeElement', () => {
);
});
const node = ensureReactNativeElement(ref.current);
const node = nullthrows(ref.current);
const callback = jest.fn();
node.measureInWindow(callback);
@@ -1518,7 +1489,7 @@ describe('ReactNativeElement', () => {
);
});
const node = ensureReactNativeElement(ref.current);
const node = nullthrows(ref.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -1550,8 +1521,8 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNode = ensureReactNativeElement(childRef.current);
const parentNode = nullthrows(parentRef.current);
const childNode = nullthrows(childRef.current);
const callback = jest.fn();
childNode.measureLayout(parentNode, callback);
@@ -1578,8 +1549,8 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNode = ensureReactNativeElement(childRef.current);
const parentNode = nullthrows(parentRef.current);
const childNode = nullthrows(childRef.current);
Fantom.runTask(() => {
root.render(
@@ -1611,8 +1582,8 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNode = ensureReactNativeElement(childRef.current);
const parentNode = nullthrows(parentRef.current);
const childNode = nullthrows(childRef.current);
Fantom.runTask(() => {
root.render(
@@ -1644,8 +1615,8 @@ describe('ReactNativeElement', () => {
);
});
const parentNode = ensureReactNativeElement(parentRef.current);
const childNode = ensureReactNativeElement(childRef.current);
const parentNode = nullthrows(parentRef.current);
const childNode = nullthrows(childRef.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -1675,7 +1646,7 @@ describe('ReactNativeElement', () => {
.toJSX(),
).toEqual(<rn-view testID={'first test id'} />);
const element = ensureReactNativeElement(nodeRef.current);
const element = nullthrows(nodeRef.current);
Fantom.runTask(() => {
element.setNativeProps({testID: 'second test id'});
@@ -1708,9 +1679,7 @@ describe('ReactNativeElement', () => {
root.render(<View ref={ref} />);
});
const element = ensureReactNativeElement(
ref.current,
) as MaybeEventTarget;
const element = nullthrows(ref.current) as MaybeEventTarget;
expect(typeof element.addEventListener).toBe('undefined');
expect(typeof element.removeEventListener).toBe('undefined');
expect(typeof element.dispatchEvent).toBe('undefined');
@@ -1753,9 +1722,7 @@ describe('ReactNativeElement', () => {
root.render(<View ref={ref} />);
});
const element = ensureReactNativeElement(
ref.current,
) as MaybeEventTarget;
const element = nullthrows(ref.current) as MaybeEventTarget;
expect(typeof element.addEventListener).toBe('function');
expect(typeof element.removeEventListener).toBe('function');
expect(typeof element.dispatchEvent).toBe('function');
@@ -1769,9 +1736,7 @@ describe('ReactNativeElement', () => {
root.render(<View ref={ref} />);
});
const element = ensureReactNativeElement(
ref.current,
) as MaybeEventTarget;
const element = nullthrows(ref.current) as MaybeEventTarget;
const listener = jest.fn();
element.addEventListener?.('custom', listener);
@@ -17,24 +17,19 @@ import type {HostInstance} from 'react-native';
import ensureInstance from '../../../../__tests__/utilities/ensureInstance';
import * as Fantom from '@react-native/fantom';
import invariant from 'invariant';
import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef} from 'react';
import {NativeText} from 'react-native/Libraries/Text/TextNativeComponent';
import {unstable_NativeText as NativeText} from 'react-native';
import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
import ReadOnlyNode from 'react-native/src/private/webapis/dom/nodes/ReadOnlyNode';
import ReadOnlyText from 'react-native/src/private/webapis/dom/nodes/ReadOnlyText';
function ensureReadOnlyText(value: unknown): ReadOnlyText {
return ensureInstance(value, ReadOnlyText);
}
function ensureReadOnlyNode(value: unknown): ReadOnlyNode {
return ensureInstance(value, ReadOnlyNode);
}
function ensureReactNativeElement(value: unknown): ReactNativeElement {
return ensureInstance(value, ReactNativeElement);
function ensureReadOnlyNode(value: unknown): Node {
return ensureInstance(value, Node);
}
// The public imperative EventTarget API is not part of the static type of this
@@ -95,7 +90,7 @@ describe('ReadOnlyText', () => {
const parentNode = ensureReadOnlyNode(parentNodeRef.current);
const textNode = parentNode.childNodes[0];
expect(textNode.nodeType).toBe(ReadOnlyNode.TEXT_NODE);
expect(textNode.nodeType).toBe(Node.TEXT_NODE);
});
});
@@ -134,10 +129,10 @@ describe('ReadOnlyText', () => {
);
});
const parentElement: ReactNativeElement = ensureReactNativeElement(
const parentElement: HostInstance = nullthrows(
parentElementRef.current,
);
const childElementA: ReactNativeElement = ensureReactNativeElement(
const childElementA: HostInstance = nullthrows(
childElementARef.current,
);
@@ -196,9 +191,7 @@ describe('ReadOnlyText', () => {
root.render(<NativeText ref={parentNodeRef}>Some text</NativeText>);
});
const parentNode: ReadOnlyNode = ensureReadOnlyNode(
parentNodeRef.current,
);
const parentNode: Node = ensureReadOnlyNode(parentNodeRef.current);
const textNode = ensureReadOnlyText(parentNode.childNodes[0]);
expect(textNode.data).toBe('Some text');
@@ -229,18 +222,10 @@ describe('ReadOnlyText', () => {
);
});
const parentElement = ensureReactNativeElement(
parentElementRef.current,
);
const childElementA = ensureReactNativeElement(
childElementARef.current,
);
const childElementB = ensureReactNativeElement(
childElementBRef.current,
);
const childElementC = ensureReactNativeElement(
childElementCRef.current,
);
const parentElement = nullthrows(parentElementRef.current);
const childElementA = nullthrows(childElementARef.current);
const childElementB = nullthrows(childElementBRef.current);
const childElementC = nullthrows(childElementCRef.current);
// Get text nodes and refine them as text nodes for Flow
const childTextA = parentElement.childNodes[0];
@@ -302,9 +287,7 @@ describe('ReadOnlyText', () => {
);
});
const parentElement = ensureReactNativeElement(
parentElementRef.current,
);
const parentElement = nullthrows(parentElementRef.current);
// Get text nodes and refine them as text nodes for Flow
const childTextA = parentElement.childNodes[0];
@@ -18,21 +18,19 @@ import * as Fantom from '@react-native/fantom';
import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef} from 'react';
import ScrollView from 'react-native/Libraries/Components/ScrollView/ScrollView';
import View from 'react-native/Libraries/Components/View/View';
import {ScrollView, View} from 'react-native';
import setUpIntersectionObserver from 'react-native/src/private/setup/setUpIntersectionObserver';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
declare const IntersectionObserver: Class<IntersectionObserverType>;
setUpIntersectionObserver();
const nodeRef = createRef<HostInstance>();
let node: ReactNativeElement;
let node: HostInstance;
const rootRef = createRef<HostInstance>();
let rootNode: ReactNativeElement;
let rootNode: HostInstance;
const scrollViewRef = createRef<HostInstance>();
let scrollViewNode: ReactNativeElement;
let scrollViewNode: HostInstance;
let observer: IntersectionObserverType;
const VIEWPORT_HEIGHT = 100;
const VIEWPORT_WIDTH = 100;
@@ -52,7 +50,7 @@ function cleanup(renderedRoot: Root, testObserver: ?IntersectionObserverType) {
}
// Scroll yOffset 1px at a time
function scrollBy1(scrollNode: ReactNativeElement, yOffset: number) {
function scrollBy1(scrollNode: HostInstance, yOffset: number) {
for (let i = 1; i <= yOffset; i++) {
Fantom.scrollTo(scrollNode, {
x: 0,
@@ -14,25 +14,19 @@ import type {HostInstance} from 'react-native';
import type IntersectionObserverType from 'react-native/src/private/webapis/intersectionobserver/IntersectionObserver';
import type IntersectionObserverEntryType from 'react-native/src/private/webapis/intersectionobserver/IntersectionObserverEntry';
import ensureInstance from '../../../__tests__/utilities/ensureInstance';
import {createShadowNodeReferenceCountingRef} from '../../../__tests__/utilities/ShadowNodeReferenceCounter';
import * as Fantom from '@react-native/fantom';
import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef, useState} from 'react';
import {ScrollView, View} from 'react-native';
import setUpIntersectionObserver from 'react-native/src/private/setup/setUpIntersectionObserver';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
import DOMRectReadOnly from 'react-native/src/private/webapis/geometry/DOMRectReadOnly';
declare const IntersectionObserver: Class<IntersectionObserverType>;
declare const IntersectionObserverEntry: Class<IntersectionObserverEntryType>;
setUpIntersectionObserver();
function ensureReactNativeElement(value: unknown): ReactNativeElement {
return ensureInstance(value, ReactNativeElement);
}
export function expectRectEquals(
rect: DOMRectReadOnly,
expected: {x: number, y: number, width: number, height: number},
@@ -287,7 +281,7 @@ describe('IntersectionObserver', () => {
root.render(<View ref={rootRef} />);
});
const rootNode = ensureReactNativeElement(rootRef.current);
const rootNode = nullthrows(rootRef.current);
Fantom.runTask(() => {
observer = new IntersectionObserver(() => {}, {root: rootNode});
@@ -601,7 +595,7 @@ describe('IntersectionObserver', () => {
root.render(<View style={{width: 100, height: 100}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -650,7 +644,7 @@ describe('IntersectionObserver', () => {
Fantom.runTask(() => {
root.render(<View style={{width: 100, height: 100}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -689,7 +683,7 @@ describe('IntersectionObserver', () => {
root.render(<View style={{width: 100, height: 100}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -722,11 +716,11 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
// Ensure View is not intersecting with ScrollView
Fantom.scrollTo(scrollNode, {x: 0, y: 200});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -787,8 +781,8 @@ describe('IntersectionObserver', () => {
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
// Scroll such that View is partially intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 25});
@@ -849,8 +843,8 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
// Scroll such that View is partially intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 25});
@@ -914,11 +908,11 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
// Ensure View is not intersecting with ScrollView
Fantom.scrollTo(scrollNode, {x: 0, y: 200});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -981,8 +975,8 @@ describe('IntersectionObserver', () => {
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
// Scroll such that View is partially intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 25});
@@ -1046,8 +1040,8 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
// Scroll such that View is partially intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 25});
@@ -1113,8 +1107,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
expect(node.isConnected).toBe(true);
@@ -1205,8 +1199,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
expect(node.isConnected).toBe(true);
@@ -1309,9 +1303,9 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const node1 = ensureReactNativeElement(maybeNode1);
const node2 = ensureReactNativeElement(maybeNode2);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node1 = nullthrows(maybeNode1);
const node2 = nullthrows(maybeNode2);
const scrollNode = nullthrows(scrollNodeRef.current);
// Scroll such that node1 is not intersecting and node 2 is intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 100});
@@ -1420,8 +1414,8 @@ describe('IntersectionObserver', () => {
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
// Scroll such that View is partially intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 25});
@@ -1485,8 +1479,8 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
// Scroll such that View is partially intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 25});
@@ -1550,8 +1544,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
expect(node.isConnected).toBe(true);
@@ -1656,9 +1650,9 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const node1 = ensureReactNativeElement(maybeNode1);
const node2 = ensureReactNativeElement(maybeNode2);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node1 = nullthrows(maybeNode1);
const node2 = nullthrows(maybeNode2);
const scrollNode = nullthrows(scrollNodeRef.current);
// Scroll such that node1 is not intersecting and node 2 is intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 100});
@@ -1774,7 +1768,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -1834,8 +1828,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const rootNode = ensureReactNativeElement(rootNodeRef.current);
const node = nullthrows(nodeRef.current);
const rootNode = nullthrows(rootNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -1895,7 +1889,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -1962,8 +1956,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const rootNode = ensureReactNativeElement(rootRef.current);
const node = nullthrows(nodeRef.current);
const rootNode = nullthrows(rootRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2027,7 +2021,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2086,7 +2080,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2145,7 +2139,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2205,8 +2199,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(rootNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(rootNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2250,8 +2244,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(rootNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(rootNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2311,8 +2305,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const customRoot = ensureReactNativeElement(rootNodeRef.current);
const node = nullthrows(nodeRef.current);
const customRoot = nullthrows(rootNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2372,7 +2366,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2428,7 +2422,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2487,7 +2481,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2546,7 +2540,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2606,8 +2600,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const rootNode = ensureReactNativeElement(rootNodeRef.current);
const node = nullthrows(nodeRef.current);
const rootNode = nullthrows(rootNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2668,8 +2662,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(rootNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(rootNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2731,7 +2725,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2783,8 +2777,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(rootNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(rootNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2843,7 +2837,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2897,7 +2891,7 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2945,8 +2939,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const intersectionObserverCallback = jest.fn();
Fantom.runTask(() => {
@@ -2979,7 +2973,7 @@ describe('IntersectionObserver', () => {
const observeRef: React.RefSetter<
React.ElementRef<typeof View>,
> = instance => {
const element = ensureReactNativeElement(instance);
const element = nullthrows(instance);
observer.observe(element);
return () => {
observer.unobserve(element);
@@ -3021,7 +3015,7 @@ describe('IntersectionObserver', () => {
return showView ? (
<View
onClick={() => {
observer.observe(ensureReactNativeElement(nodeRef.current));
observer.observe(nullthrows(nodeRef.current));
setShowView(false);
}}
style={{width: 100, height: 100, backgroundColor: 'red'}}
@@ -3034,7 +3028,7 @@ describe('IntersectionObserver', () => {
root.render(<TestComponent />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(node.isConnected).toBe(true);
@@ -3068,7 +3062,7 @@ describe('IntersectionObserver', () => {
root.render(<View style={{width: 100, height: 100}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -3127,8 +3121,8 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
Fantom.scrollTo(scrollNode, {x: 0, y: 25});
@@ -3188,8 +3182,8 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
Fantom.scrollTo(scrollNode, {x: 0, y: 200});
@@ -3263,8 +3257,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
// Scroll such that target View is not intersecting
Fantom.scrollTo(scrollNode, {x: 0, y: 2000});
@@ -3371,7 +3365,7 @@ describe('IntersectionObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node1 = nullthrows(node1Ref.current);
const intersectionObserverCallback = jest.fn();
@@ -3445,8 +3439,8 @@ describe('IntersectionObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const intersectionObserverCallback = jest.fn();
@@ -3515,7 +3509,7 @@ describe('IntersectionObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node1 = nullthrows(node1Ref.current);
const intersectionObserverCallback = jest.fn();
@@ -3585,8 +3579,8 @@ describe('IntersectionObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const intersectionObserverCallback = jest.fn();
@@ -3652,8 +3646,8 @@ describe('IntersectionObserver', () => {
</View>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const rootNode = ensureReactNativeElement(rootRef.current);
const node = nullthrows(nodeRef.current);
const rootNode = nullthrows(rootRef.current);
const intersectionObserverCallback = jest.fn();
@@ -3717,8 +3711,8 @@ describe('IntersectionObserver', () => {
</View>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const rootNode = ensureReactNativeElement(rootRef.current);
const node = nullthrows(nodeRef.current);
const rootNode = nullthrows(rootRef.current);
const intersectionObserverCallback = jest.fn();
@@ -3783,8 +3777,8 @@ describe('IntersectionObserver', () => {
</View>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const rootNode = ensureReactNativeElement(rootRef.current);
const node = nullthrows(nodeRef.current);
const rootNode = nullthrows(rootRef.current);
const intersectionObserverCallback = jest.fn();
@@ -3847,8 +3841,8 @@ describe('IntersectionObserver', () => {
</View>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const rootNode = ensureReactNativeElement(rootRef.current);
const node = nullthrows(nodeRef.current);
const rootNode = nullthrows(rootRef.current);
const intersectionObserverCallback = jest.fn();
@@ -3914,8 +3908,8 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -3965,7 +3959,7 @@ describe('IntersectionObserver', () => {
</ScrollView>,
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -4005,7 +3999,7 @@ describe('IntersectionObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -4030,8 +4024,8 @@ describe('IntersectionObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const node = nullthrows(nodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
Fantom.scrollTo(scrollNode, {x: 0, y: 100});
@@ -4073,7 +4067,7 @@ describe('IntersectionObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
@@ -4106,7 +4100,7 @@ describe('IntersectionObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -4126,7 +4120,7 @@ describe('IntersectionObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -4155,7 +4149,7 @@ describe('IntersectionObserver', () => {
);
});
const scrollNode = ensureReactNativeElement(scrollNodeRef.current);
const scrollNode = nullthrows(scrollNodeRef.current);
// Scroll such that view is not intersecting with ScrollView
Fantom.scrollTo(scrollNode, {
@@ -4163,7 +4157,7 @@ describe('IntersectionObserver', () => {
y: 100,
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
@@ -4216,8 +4210,8 @@ describe('IntersectionObserver', () => {
</>,
);
});
const node1 = ensureReactNativeElement(maybeNode1);
const node2 = ensureReactNativeElement(maybeNode2);
const node1 = nullthrows(maybeNode1);
const node2 = nullthrows(maybeNode2);
const intersectionObserverCallback = jest.fn();
@@ -4273,7 +4267,7 @@ describe('IntersectionObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
observer1 = new IntersectionObserver(() => {});
@@ -4325,8 +4319,8 @@ describe('IntersectionObserver', () => {
</>,
);
});
const node1 = ensureReactNativeElement(maybeNode1);
const node2 = ensureReactNativeElement(maybeNode2);
const node1 = nullthrows(maybeNode1);
const node2 = nullthrows(maybeNode2);
const callback = jest.fn();
@@ -4354,7 +4348,7 @@ describe('IntersectionObserver', () => {
root.render(<View ref={nodeRef} style={{width: 100, height: 100}} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const intersectionObserverCallback = jest.fn();
@@ -22,17 +22,12 @@ import * as React from 'react';
import {createRef} from 'react';
import {View} from 'react-native';
import setUpMutationObserver from 'react-native/src/private/setup/setUpMutationObserver';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
declare const MutationObserver: Class<MutationObserverType>;
declare const MutationRecord: Class<MutationRecordType>;
setUpMutationObserver();
function ensureReactNativeElement(value: unknown): ReactNativeElement {
return ensureInstance(value, ReactNativeElement);
}
function ensureMutationRecordArray(
value: unknown,
): ReadonlyArray<MutationRecord> {
@@ -81,7 +76,7 @@ describe('MutationObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(() => {
const observer = new MutationObserver(() => {});
@@ -118,7 +113,7 @@ describe('MutationObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(() => {
const observer = new MutationObserver(() => {});
@@ -136,7 +131,7 @@ describe('MutationObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(() => {
const observer = new MutationObserver(() => {});
@@ -154,7 +149,7 @@ describe('MutationObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(() => {
const observer = new MutationObserver(() => {});
@@ -173,7 +168,7 @@ describe('MutationObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(() => {
const observer = new MutationObserver(() => {});
@@ -191,7 +186,7 @@ describe('MutationObserver', () => {
root.render(<View ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(() => {
const observer = new MutationObserver(() => {});
@@ -212,7 +207,7 @@ describe('MutationObserver', () => {
root.render(<View key="node1" ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -236,7 +231,7 @@ describe('MutationObserver', () => {
root.render(<View key="node1" ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const observerCallbackCallArgs = [];
const observerCallback = (...args: ReadonlyArray<unknown>) => {
@@ -260,8 +255,8 @@ describe('MutationObserver', () => {
);
});
const childNode1 = ensureReactNativeElement(childNode1Ref.current);
const childNode2 = ensureReactNativeElement(childNode2Ref.current);
const childNode1 = nullthrows(childNode1Ref.current);
const childNode2 = nullthrows(childNode2Ref.current);
expect(observerCallbackCallArgs.length).toBe(1);
const firstCall = nullthrows(observerCallbackCallArgs.at(-1));
@@ -322,7 +317,7 @@ describe('MutationObserver', () => {
);
});
const observedNode = ensureReactNativeElement(observedNodeRef.current);
const observedNode = nullthrows(observedNodeRef.current);
const observerCallback = jest.fn();
const observer = new MutationObserver(observerCallback);
@@ -366,7 +361,7 @@ describe('MutationObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const observerCallback = jest.fn();
const observer = new MutationObserver(observerCallback);
@@ -387,7 +382,7 @@ describe('MutationObserver', () => {
);
});
const node111 = ensureReactNativeElement(node111Ref.current);
const node111 = nullthrows(node111Ref.current);
expect(observerCallback).toHaveBeenCalledTimes(1);
const firstCall = observerCallback.mock.lastCall;
@@ -426,7 +421,7 @@ describe('MutationObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const observerCallback = jest.fn();
const observer = new MutationObserver(observerCallback);
@@ -451,8 +446,8 @@ describe('MutationObserver', () => {
);
});
const node111 = ensureReactNativeElement(node111Ref.current);
const node121 = ensureReactNativeElement(node121Ref.current);
const node111 = nullthrows(node111Ref.current);
const node121 = nullthrows(node121Ref.current);
expect(observerCallback).toHaveBeenCalledTimes(1);
const firstCall = observerCallback.mock.lastCall;
@@ -499,8 +494,8 @@ describe('MutationObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const observerCallback1 = jest.fn();
const observer1 = new MutationObserver(observerCallback1);
@@ -530,8 +525,8 @@ describe('MutationObserver', () => {
);
});
const childNode11 = ensureReactNativeElement(childNode11Ref.current);
const childNode21 = ensureReactNativeElement(childNode21Ref.current);
const childNode11 = nullthrows(childNode11Ref.current);
const childNode21 = nullthrows(childNode21Ref.current);
expect(observerCallback1).toHaveBeenCalledTimes(1);
const observer1Records1 = ensureMutationRecordArray(
@@ -588,8 +583,8 @@ describe('MutationObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const observerCallback1 = jest.fn();
const observer1 = new MutationObserver(observerCallback1);
@@ -615,7 +610,7 @@ describe('MutationObserver', () => {
);
});
const childNode111 = ensureReactNativeElement(childNode111Ref.current);
const childNode111 = nullthrows(childNode111Ref.current);
expect(observerCallback1).toHaveBeenCalledTimes(1);
const observer1Records1 = ensureMutationRecordArray(
@@ -675,8 +670,8 @@ describe('MutationObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const observerCallback = jest.fn();
const observer = new MutationObserver(observerCallback);
@@ -702,8 +697,8 @@ describe('MutationObserver', () => {
);
});
const childNode11 = ensureReactNativeElement(childNode11Ref.current);
const childNode21 = ensureReactNativeElement(childNode21Ref.current);
const childNode11 = nullthrows(childNode11Ref.current);
const childNode21 = nullthrows(childNode21Ref.current);
expect(observerCallback).toHaveBeenCalledTimes(1);
const records = ensureMutationRecordArray(
@@ -748,8 +743,8 @@ describe('MutationObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node11 = ensureReactNativeElement(node11Ref.current);
const node1 = nullthrows(node1Ref.current);
const node11 = nullthrows(node11Ref.current);
const observerCallback = jest.fn();
const observer = new MutationObserver(observerCallback);
@@ -771,7 +766,7 @@ describe('MutationObserver', () => {
);
});
const childNode111 = ensureReactNativeElement(childNode111Ref.current);
const childNode111 = nullthrows(childNode111Ref.current);
expect(observerCallback).toHaveBeenCalledTimes(1);
const records = ensureMutationRecordArray(
@@ -818,7 +813,7 @@ describe('MutationObserver', () => {
});
Fantom.runTask(() => {
observer.observe(ensureReactNativeElement(parentRef.current), {
observer.observe(nullthrows(parentRef.current), {
childList: true,
});
});
@@ -845,7 +840,7 @@ describe('MutationObserver', () => {
root.render(<View key="node1" ref={observedNodeRef} />);
});
const observedNode = ensureReactNativeElement(observedNodeRef.current);
const observedNode = nullthrows(observedNodeRef.current);
const observerCallback = jest.fn();
const observer = new MutationObserver(observerCallback);
@@ -886,7 +881,7 @@ describe('MutationObserver', () => {
root.render(<View key="node1" ref={observedNodeRef} />);
});
const observedNode = ensureReactNativeElement(observedNodeRef.current);
const observedNode = nullthrows(observedNodeRef.current);
const observerCallback = jest.fn();
const observer = new MutationObserver(observerCallback);
@@ -911,7 +906,7 @@ describe('MutationObserver', () => {
root.render(<View key="node1" ref={observedNodeRef} />);
});
const observedNode = ensureReactNativeElement(observedNodeRef.current);
const observedNode = nullthrows(observedNodeRef.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -16,15 +16,13 @@ import type ResizeObserverType from 'react-native/src/private/webapis/resizeobse
import type ResizeObserverEntryType from 'react-native/src/private/webapis/resizeobserver/ResizeObserverEntry';
import type ResizeObserverSizeType from 'react-native/src/private/webapis/resizeobserver/ResizeObserverSize';
import ensureInstance from '../../../__tests__/utilities/ensureInstance';
import {createShadowNodeReferenceCountingRef} from '../../../__tests__/utilities/ShadowNodeReferenceCounter';
import * as Fantom from '@react-native/fantom';
import nullthrows from 'nullthrows';
import * as React from 'react';
import {createRef} from 'react';
import {View} from 'react-native';
import setUpResizeObserver from 'react-native/src/private/setup/setUpResizeObserver';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
import DOMRectReadOnly from 'react-native/src/private/webapis/geometry/DOMRectReadOnly';
declare const ResizeObserver: Class<ResizeObserverType>;
declare const ResizeObserverEntry: Class<ResizeObserverEntryType>;
@@ -37,10 +35,6 @@ type ResizeObserverMockCallback = JestMockFn<
setUpResizeObserver();
function ensureReactNativeElement(value: unknown): ReactNativeElement {
return ensureInstance(value, ReactNativeElement);
}
function expectEntrySizes(
entry: ResizeObserverEntry,
expected: {
@@ -145,7 +139,7 @@ describe('ResizeObserver', () => {
Fantom.runTask(() => {
root.render(<View style={{width: 10, height: 10}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
observer = new ResizeObserver(() => {});
expect(() => {
@@ -162,7 +156,7 @@ describe('ResizeObserver', () => {
Fantom.runTask(() => {
root.render(<View style={{width: 10, height: 10}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
expect(() => {
observer = new ResizeObserver(() => {});
@@ -181,7 +175,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 10, height: 10}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
root.render(<></>);
@@ -207,7 +201,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -239,7 +233,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 0, height: 0}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -275,7 +269,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -306,7 +300,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 10.4, height: 10.6}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -332,7 +326,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -361,7 +355,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -392,7 +386,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -431,7 +425,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -484,7 +478,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -548,7 +542,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -587,7 +581,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -634,7 +628,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -672,7 +666,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -706,7 +700,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -761,7 +755,7 @@ describe('ResizeObserver', () => {
);
});
const child = ensureReactNativeElement(childRef.current);
const child = nullthrows(childRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -808,7 +802,7 @@ describe('ResizeObserver', () => {
);
});
const child = ensureReactNativeElement(childRef.current);
const child = nullthrows(childRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -873,7 +867,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback1 = jest.fn();
const callback2 = jest.fn();
@@ -914,7 +908,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -958,7 +952,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -990,7 +984,7 @@ describe('ResizeObserver', () => {
// shown again. Web-style reinsertion of the *same* Element is not
// expressible via React remount.
expect(callback).toHaveBeenCalledTimes(2);
const remountedNode = ensureReactNativeElement(nodeRef.current);
const remountedNode = nullthrows(nodeRef.current);
expect(remountedNode).not.toBe(node);
Fantom.runTask(() => {
@@ -1020,7 +1014,7 @@ describe('ResizeObserver', () => {
);
});
const child = ensureReactNativeElement(childRef.current);
const child = nullthrows(childRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -1053,8 +1047,8 @@ describe('ResizeObserver', () => {
);
});
const nodeA = ensureReactNativeElement(nodeARef.current);
const nodeB = ensureReactNativeElement(nodeBRef.current);
const nodeA = nullthrows(nodeARef.current);
const nodeB = nullthrows(nodeBRef.current);
const callbackB = jest.fn();
let observerB: ResizeObserver;
@@ -1104,8 +1098,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
Fantom.runTask(() => {
observer1 = new ResizeObserver(callback1);
@@ -1159,7 +1153,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -1208,8 +1202,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -1283,8 +1277,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const callback1 = jest.fn();
const callback2 = jest.fn();
@@ -1360,8 +1354,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -1422,8 +1416,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const callOrder: Array<string> = [];
const callbackA: ResizeObserverMockCallback = jest.fn(() =>
@@ -1492,8 +1486,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const callOrder: Array<string> = [];
const callbackA: ResizeObserverMockCallback = jest.fn(() =>
@@ -1536,7 +1530,7 @@ describe('ResizeObserver', () => {
const observeRef: React.RefSetter<
React.ElementRef<typeof View>,
> = instance => {
const element = ensureReactNativeElement(instance);
const element = nullthrows(instance);
observer.observe(element);
return () => {
observer.unobserve(element);
@@ -1579,7 +1573,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const events: Array<string> = [];
const callback: ResizeObserverMockCallback = jest.fn(() => {
events.push('callback');
@@ -1609,7 +1603,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const observed: Array<string> = [];
const callback: ResizeObserverMockCallback = jest.fn(entries => {
observed.push(
@@ -1643,7 +1637,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback1: ResizeObserverMockCallback = jest.fn(() => {
throw new Error('observer 1 failed');
});
@@ -1687,7 +1681,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback: ResizeObserverMockCallback = jest.fn(() => {
throw new Error('observer failed');
});
@@ -1745,7 +1739,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
let selfObserver: ResizeObserver;
const callback: ResizeObserverMockCallback = jest.fn(() => {
selfObserver.disconnect();
@@ -1782,8 +1776,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
let observerA: ResizeObserver;
let observerB: ResizeObserver;
@@ -1830,9 +1824,9 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node3 = ensureReactNativeElement(node3Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const node3 = nullthrows(node3Ref.current);
let observerA: ResizeObserver;
let observerB: ResizeObserver;
@@ -1893,7 +1887,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
let firstObserver: ResizeObserver;
// Disconnecting the only observer tears down the whole native
// connection (commit hook, event-loop delegate, notification callback)
@@ -1948,8 +1942,8 @@ describe('ResizeObserver', () => {
);
});
const nodeA = ensureReactNativeElement(nodeARef.current);
const nodeB = ensureReactNativeElement(nodeBRef.current);
const nodeA = nullthrows(nodeARef.current);
const nodeB = nullthrows(nodeBRef.current);
// Re-enters `observe()` on the very observer being notified. Re-observing
// an already-observed target with the same box is a no-op, so this
@@ -2016,8 +2010,8 @@ describe('ResizeObserver', () => {
);
});
const nodeA = ensureReactNativeElement(nodeARef.current);
const nodeB = ensureReactNativeElement(nodeBRef.current);
const nodeA = nullthrows(nodeARef.current);
const nodeB = nullthrows(nodeBRef.current);
const callback: ResizeObserverMockCallback = jest.fn(() => {
observer.observe(nodeA);
});
@@ -2074,7 +2068,7 @@ describe('ResizeObserver', () => {
root.render(<Box />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback: ResizeObserverMockCallback = jest.fn(entries => {
events.push(`callback:${entries[0].contentRect.width}`);
@@ -2125,7 +2119,7 @@ describe('ResizeObserver', () => {
root.render(<Box />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback: ResizeObserverMockCallback = jest.fn(() => {
const setWidth = setWidthRef.current;
if (setWidth != null && widthMeasuredAfterSetState === -1) {
@@ -2164,7 +2158,7 @@ describe('ResizeObserver', () => {
root.render(<Box />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback: ResizeObserverMockCallback = jest.fn(() => {
const setSize = setSizeRef.current;
if (setSize != null && renderCount < 2) {
@@ -2220,8 +2214,8 @@ describe('ResizeObserver', () => {
root.render(<Boxes />);
});
const nodeA = ensureReactNativeElement(nodeARef.current);
const nodeB = ensureReactNativeElement(nodeBRef.current);
const nodeA = nullthrows(nodeARef.current);
const nodeB = nullthrows(nodeBRef.current);
let scheduled = false;
const callbackA: ResizeObserverMockCallback = jest.fn(() => {
if (!scheduled) {
@@ -2281,8 +2275,8 @@ describe('ResizeObserver', () => {
root.render(<Boxes />);
});
const nodeA = ensureReactNativeElement(nodeARef.current);
const nodeB = ensureReactNativeElement(nodeBRef.current);
const nodeA = nullthrows(nodeARef.current);
const nodeB = nullthrows(nodeBRef.current);
let resizedBInCallback = false;
const callbackA: ResizeObserverMockCallback = jest.fn(() => {
if (!resizedBInCallback) {
@@ -2343,8 +2337,8 @@ describe('ResizeObserver', () => {
root.render(<Boxes />);
});
const nodeA = ensureReactNativeElement(nodeARef.current);
const nodeB = ensureReactNativeElement(nodeBRef.current);
const nodeA = nullthrows(nodeARef.current);
const nodeB = nullthrows(nodeBRef.current);
const callbackA: ResizeObserverMockCallback = jest.fn(() => {
deliveryOrder.push('A');
@@ -2401,8 +2395,8 @@ describe('ResizeObserver', () => {
root.render(<Boxes />);
});
const nodeA = ensureReactNativeElement(nodeARef.current);
const nodeB = ensureReactNativeElement(nodeBRef.current);
const nodeA = nullthrows(nodeARef.current);
const nodeB = nullthrows(nodeBRef.current);
// Each callback grows the other target every time it is notified, with no
// guard to stop the cycle. It settles only because the sizes converge on
@@ -2473,7 +2467,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 10, height: 10}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -2494,7 +2488,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -2524,7 +2518,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -2557,7 +2551,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -2579,7 +2573,7 @@ describe('ResizeObserver', () => {
);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -2615,7 +2609,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
observer1 = new ResizeObserver(callback1);
@@ -2681,8 +2675,8 @@ describe('ResizeObserver', () => {
);
});
const node1 = ensureReactNativeElement(node1Ref.current);
const node2 = ensureReactNativeElement(node2Ref.current);
const node1 = nullthrows(node1Ref.current);
const node2 = nullthrows(node2Ref.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -2721,7 +2715,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
observer = new ResizeObserver(callback);
@@ -2744,7 +2738,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -2781,7 +2775,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
observer = new ResizeObserver(() => {});
@@ -2809,7 +2803,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
Fantom.runTask(() => {
observer = new ResizeObserver(callback);
@@ -2844,7 +2838,7 @@ describe('ResizeObserver', () => {
root.render(<View style={{width: 100, height: 50}} ref={nodeRef} />);
});
const node = ensureReactNativeElement(nodeRef.current);
const node = nullthrows(nodeRef.current);
const callback = jest.fn();
Fantom.runTask(() => {
@@ -20,7 +20,6 @@ import {createRef} from 'react';
import {View} from 'react-native';
import setUpIntersectionObserver from 'react-native/src/private/setup/setUpIntersectionObserver';
import setUpMutationObserver from 'react-native/src/private/setup/setUpMutationObserver';
import EventTarget from 'react-native/src/private/webapis/dom/events/EventTarget';
import DOMException from 'react-native/src/private/webapis/errors/DOMException';
import IntersectionObserver from 'react-native/src/private/webapis/intersectionobserver/IntersectionObserver';
import IntersectionObserverEntry from 'react-native/src/private/webapis/intersectionobserver/IntersectionObserverEntry';
+24 -37
View File
@@ -17,10 +17,15 @@ import * as Fantom from '@react-native/fantom';
import * as React from 'react';
import {createRef} from 'react';
import {LogBox, Modal, ScrollView, Text, TextInput, View} from 'react-native';
import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance';
import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom';
import ReactNativeDocument from 'react-native/src/private/webapis/dom/nodes/ReactNativeDocument';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
function ensureHostInstance(value: HostInstance | null): HostInstance {
if (value == null) {
throw new Error(`Expected host instance but got ${String(value)}`);
}
expect(value).toBeInstanceOf(HTMLElement);
return value;
}
function getActualViewportDimensions(root: Root): {
viewportWidth: number,
@@ -343,7 +348,7 @@ describe('Fantom', () => {
root.render(<></>);
});
expect(root.document).toBeInstanceOf(ReactNativeDocument);
expect(root.document).toBeInstanceOf(Document);
});
});
@@ -556,7 +561,7 @@ describe('Fantom', () => {
root.render(<TextInput onFocus={focusEvent} ref={ref} />);
});
const element = ensureInstance(ref.current, ReactNativeElement);
const element = ensureHostInstance(ref.current);
expect(focusEvent).toHaveBeenCalledTimes(0);
@@ -613,7 +618,7 @@ describe('Fantom', () => {
);
});
const element = ensureInstance(ref.current, ReactNativeElement);
const element = ensureHostInstance(ref.current);
Fantom.runOnUIThread(() => {
Fantom.enqueueNativeEvent(element, 'change', {
@@ -644,7 +649,7 @@ describe('Fantom', () => {
);
});
const element = ensureInstance(ref.current, ReactNativeElement);
const element = ensureHostInstance(ref.current);
Fantom.runOnUIThread(() => {
Fantom.enqueueNativeEvent(
@@ -697,7 +702,7 @@ describe('Fantom', () => {
root.render(<TextInput onFocus={focusEvent} ref={ref} />);
});
const element = ensureInstance(ref.current, ReactNativeElement);
const element = ensureHostInstance(ref.current);
expect(focusEvent).toHaveBeenCalledTimes(0);
@@ -733,7 +738,7 @@ describe('Fantom', () => {
root.render(<View ref={ref} />);
});
const element = ensureInstance(ref.current, ReactNativeElement);
const element = ensureHostInstance(ref.current);
expect(() => {
Fantom.runOnUIThread(() => {
@@ -765,10 +770,7 @@ describe('Fantom', () => {
);
});
const scrollViewElement = ensureInstance(
scrollViewRef.current,
ReactNativeElement,
);
const scrollViewElement = ensureHostInstance(scrollViewRef.current);
Fantom.runOnUIThread(() => {
Fantom.enqueueScrollEvent(scrollViewElement, {
@@ -781,7 +783,7 @@ describe('Fantom', () => {
expect(onScroll).toHaveBeenCalledTimes(1);
const viewElement = ensureInstance(viewRef.current, ReactNativeElement);
const viewElement = ensureHostInstance(viewRef.current);
let rect;
@@ -854,7 +856,7 @@ describe('Fantom', () => {
root.render(<View ref={ref} />);
});
const element = ensureInstance(ref.current, ReactNativeElement);
const element = ensureHostInstance(ref.current);
expect(() => {
Fantom.scrollTo(element, {
@@ -884,10 +886,7 @@ describe('Fantom', () => {
);
});
const scrollViewElement = ensureInstance(
scrollViewRef.current,
ReactNativeElement,
);
const scrollViewElement = ensureHostInstance(scrollViewRef.current);
expect(scrollViewElement.scrollTop).toBe(0);
@@ -900,7 +899,7 @@ describe('Fantom', () => {
expect(onScroll).toHaveBeenCalledTimes(1);
const viewElement = ensureInstance(viewRef.current, ReactNativeElement);
const viewElement = ensureHostInstance(viewRef.current);
let rect;
@@ -951,10 +950,7 @@ describe('Fantom', () => {
);
});
const scrollViewElement = ensureInstance(
scrollViewRef.current,
ReactNativeElement,
);
const scrollViewElement = ensureHostInstance(scrollViewRef.current);
expect(scrollViewElement.scrollTop).toBe(0);
@@ -999,7 +995,7 @@ describe('Fantom', () => {
root.render(<View ref={ref} />);
});
const element = ensureInstance(ref.current, ReactNativeElement);
const element = ensureHostInstance(ref.current);
expect(() => {
Fantom.runOnUIThread(() => {
@@ -1026,10 +1022,7 @@ describe('Fantom', () => {
);
});
const modalElement = ensureInstance(
modalNodeRef.current,
ReactNativeElement,
);
const modalElement = ensureHostInstance(modalNodeRef.current);
Fantom.runOnUIThread(() => {
Fantom.enqueueModalSizeUpdate(modalElement, {
@@ -1040,10 +1033,7 @@ describe('Fantom', () => {
Fantom.runWorkLoop();
const viewElement = ensureInstance(
viewNodeRef.current,
ReactNativeElement,
);
const viewElement = ensureHostInstance(viewNodeRef.current);
const boundingClientRect = viewElement.getBoundingClientRect();
expect(boundingClientRect.height).toBe(25);
@@ -1072,10 +1062,7 @@ describe('Fantom', () => {
Fantom.runWorkLoop();
const viewElement = ensureInstance(
viewNodeRef.current,
ReactNativeElement,
);
const viewElement = ensureHostInstance(viewNodeRef.current);
const boundingClientRect = viewElement.getBoundingClientRect();
expect(boundingClientRect.height).toBe(25);