Add a few more tests to ReactNativeElement (#48428)

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

Changelog: [internal]

Adding a few more tests for `ReactNativeElement` for symmetry with future tests for when it implements `EventTarget`.

Reviewed By: javache

Differential Revision: D67738147

fbshipit-source-id: 04c8f3539fefd15f7c778986eb9e39f2c2386b6a
This commit is contained in:
Rubén Norte
2025-01-09 03:45:27 -08:00
committed by Facebook GitHub Bot
parent 5e6478954c
commit 742e14d47f
@@ -22,6 +22,7 @@ import ensureInstance from '../../../../utilities/ensureInstance';
import HTMLCollection from '../../oldstylecollections/HTMLCollection';
import NodeList from '../../oldstylecollections/NodeList';
import ReactNativeElement from '../ReactNativeElement';
import ReadOnlyElement from '../ReadOnlyElement';
import ReadOnlyNode from '../ReadOnlyNode';
import * as Fantom from '@react-native/fantom';
import * as React from 'react';
@@ -51,6 +52,23 @@ describe('ReactNativeElement', () => {
});
describe('extends `ReadOnlyNode`', () => {
it('should be an instance of `ReadOnlyNode`', () => {
let lastNode;
const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(
<View
ref={node => {
lastNode = node;
}}
/>,
);
});
expect(lastNode).toBeInstanceOf(ReadOnlyNode);
});
describe('nodeType', () => {
it('returns ReadOnlyNode.ELEMENT_NODE', () => {
let lastParentNode;
@@ -773,6 +791,23 @@ describe('ReactNativeElement', () => {
});
describe('extends `ReadOnlyElement`', () => {
it('should be an instance of `ReadOnlyElement`', () => {
let lastNode;
const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(
<View
ref={node => {
lastNode = node;
}}
/>,
);
});
expect(lastNode).toBeInstanceOf(ReadOnlyElement);
});
describe('children / childElementCount', () => {
it('return updated element children information', () => {
let lastParentElement;
@@ -1287,7 +1322,26 @@ describe('ReactNativeElement', () => {
});
});
describe('implements specific `ReactNativeElement` methods', () => {
describe('extends `ReactNativeElement`', () => {
it('should be an instance of `ReactNativeElement`', () => {
let lastNode;
// Initial render with 3 children
const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(
<View
ref={node => {
lastNode = node;
}}
/>,
);
});
const node = ensureReactNativeElement(lastNode);
expect(node).toBeInstanceOf(ReactNativeElement);
});
describe('offsetWidth / offsetHeight', () => {
it('return the rounded width and height, or 0 when disconnected', () => {
let lastElement;