From 7a5ab34451caec6145454d16a2fce56e752ad26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 8 Jul 2026 00:45:28 -0700 Subject: [PATCH] Document Fantom convention: prefer testing through the public API (#57467) Summary: Pull Request resolved: https://github.com/react/react-native/pull/57467 Adds a convention to the Fantom README recommending that tests exercise React Native through its public API (importing from `react-native`) whenever possible, rather than reaching into internal modules. Exercising the public surface also drives the underlying native (Fabric/TurboModules) code, so tests stay close to real usage and are more resilient to internal refactors. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D110918650 fbshipit-source-id: b19dc4b4a380030196a4e83890aae6720a64c77f --- private/react-native-fantom/__docs__/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/private/react-native-fantom/__docs__/README.md b/private/react-native-fantom/__docs__/README.md index e54b1918075..d5997c130e8 100644 --- a/private/react-native-fantom/__docs__/README.md +++ b/private/react-native-fantom/__docs__/README.md @@ -180,6 +180,19 @@ hi ### Conventions +- Prefer testing React Native through its public API (import from + `'react-native'`) whenever possible, rather than reaching into internal + modules or relying on private/protected members (e.g. `__`-prefixed methods + and fields such as `__getValue()`). Exercising the public API also drives the + underlying native (Fabric/TurboModules) code, so tests stay close to real + usage and are more resilient to internal refactors. Observe results through + the public surface too — e.g. assert the rendered output + (`root.getRenderedOutput(...)`) or values delivered to public listeners + rather than reading private state. + - When Fantom doesn't support something (a native module, a capability, a way + to observe a result, etc.), it's fine to reach into internals to work around + that limitation. Prefer a short comment explaining why the internal access is + necessary. - Place test files in `__tests__` directories alongside the code being tested. - Benchmark tests use the `-benchmark-itest.js` suffix. - Use `Fantom.runTask()` to render and run synchronous operations; it ensures