Skip to content

Commit 7a5ab34

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Document Fantom convention: prefer testing through the public API (#57467)
Summary: Pull Request resolved: #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
1 parent 5e64e90 commit 7a5ab34

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • private/react-native-fantom/__docs__

private/react-native-fantom/__docs__/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ hi
180180

181181
### Conventions
182182

183+
- Prefer testing React Native through its public API (import from
184+
`'react-native'`) whenever possible, rather than reaching into internal
185+
modules or relying on private/protected members (e.g. `__`-prefixed methods
186+
and fields such as `__getValue()`). Exercising the public API also drives the
187+
underlying native (Fabric/TurboModules) code, so tests stay close to real
188+
usage and are more resilient to internal refactors. Observe results through
189+
the public surface too — e.g. assert the rendered output
190+
(`root.getRenderedOutput(...)`) or values delivered to public listeners
191+
rather than reading private state.
192+
- When Fantom doesn't support something (a native module, a capability, a way
193+
to observe a result, etc.), it's fine to reach into internals to work around
194+
that limitation. Prefer a short comment explaining why the internal access is
195+
necessary.
183196
- Place test files in `__tests__` directories alongside the code being tested.
184197
- Benchmark tests use the `-benchmark-itest.js` suffix.
185198
- Use `Fantom.runTask()` to render and run synchronous operations; it ensures

0 commit comments

Comments
 (0)