diff --git a/packages/react-native/Libraries/Image/__tests__/Image-itest.js b/packages/react-native/Libraries/Image/__tests__/Image-itest.js index 1cd5750d2a6..2c02271372c 100644 --- a/packages/react-native/Libraries/Image/__tests__/Image-itest.js +++ b/packages/react-native/Libraries/Image/__tests__/Image-itest.js @@ -19,6 +19,7 @@ import * as React from 'react'; import {createRef} from 'react'; import {Image} from 'react-native'; import accessibilityPropsSuite from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite'; +import {testIDPropSuite} from 'react-native/src/private/__tests__/utilities/commonPropsSuite'; import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance'; import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom'; import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement'; @@ -582,20 +583,6 @@ describe('', () => { }); }); - describe('testID', () => { - it('can be set', () => { - const root = Fantom.createRoot(); - - Fantom.runTask(() => { - root.render(); - }); - - expect(root.getRenderedOutput({props: ['testID']}).toJSX()).toEqual( - , - ); - }); - }); - describe('tintColor', () => { it('can be set', () => { const root = Fantom.createRoot(); @@ -610,11 +597,12 @@ describe('', () => { }); }); - component ComponentWithAccessibilityProps(...props: AccessibilityProps) { - return ; + component TestComponent(testID?: ?string, ...props: AccessibilityProps) { + return ; } - accessibilityPropsSuite(ComponentWithAccessibilityProps, false); + accessibilityPropsSuite(TestComponent, false); + testIDPropSuite(TestComponent); }); describe('ref', () => { diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index 2a05b002bb3..785fe029342 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -21,6 +21,7 @@ import {Text} from 'react-native'; import accessibilityPropsSuite, { rolePropSuite, } from 'react-native/src/private/__tests__/utilities/accessibilityPropsSuite'; +import {testIDPropSuite} from 'react-native/src/private/__tests__/utilities/commonPropsSuite'; import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement'; import ReadOnlyText from 'react-native/src/private/webapis/dom/nodes/ReadOnlyText'; @@ -418,9 +419,15 @@ describe('', () => { }); }); - component ComponentWithAccessibilityProps(...props: AccessibilityProps) { - return {TEST_TEXT}; + component TestComponent(testID?: ?string, ...props: AccessibilityProps) { + return ( + + {TEST_TEXT} + + ); } - accessibilityPropsSuite(ComponentWithAccessibilityProps, false); - rolePropSuite(ComponentWithAccessibilityProps); + accessibilityPropsSuite(TestComponent, false); + rolePropSuite(TestComponent); + + testIDPropSuite(TestComponent); }); diff --git a/packages/react-native/src/private/__tests__/utilities/commonPropsSuite.js b/packages/react-native/src/private/__tests__/utilities/commonPropsSuite.js new file mode 100644 index 00000000000..1690bf5c384 --- /dev/null +++ b/packages/react-native/src/private/__tests__/utilities/commonPropsSuite.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +import type {Root} from '@react-native/fantom'; + +import * as Fantom from '@react-native/fantom'; +import * as React from 'react'; + +export function testIDPropSuite( + Component: component(...{testID?: ?string}), +): void { + let root: Root; + + beforeEach(() => { + root = Fantom.createRoot(); + }); + + afterEach(() => { + root.destroy(); + }); + + describe('testID', () => { + it('can be set', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['testID']}).toJSONObject().props.testID, + ).toEqual('test'); + }); + }); +}