Skip to content

Commit

Permalink
[skip ci] Add a few more tests to ReactNativeElement (facebook#48428)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [internal]

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

Differential Revision: D67738147
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 4, 2025
1 parent 4d875f8 commit 2a1c13a
Showing 1 changed file with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +52,24 @@ describe('ReactNativeElement', () => {
});

describe('extends `ReadOnlyNode`', () => {
it('should be an instance of `ReadOnlyNode`', () => {
let lastNode;

// Initial render with 3 children
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;
Expand Down Expand Up @@ -773,6 +792,24 @@ describe('ReactNativeElement', () => {
});

describe('extends `ReadOnlyElement`', () => {
it('should be an instance of `ReadOnlyElement`', () => {
let lastNode;

// Initial render with 3 children
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;
Expand Down Expand Up @@ -1287,7 +1324,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;
Expand Down

0 comments on commit 2a1c13a

Please sign in to comment.