Skip to content

Commit 1ad1cef

Browse files
committed
.
1 parent 7600515 commit 1ad1cef

File tree

6 files changed

+47
-56
lines changed

6 files changed

+47
-56
lines changed

website/docs/12.x/docs/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
uri: /api
33
---
4+
45
# API Overview
56

67
React Native Testing Library consists of following APIs:
@@ -12,10 +13,9 @@ React Native Testing Library consists of following APIs:
1213
- Helpers: [`debug`](docs/api/screen#debug), [`toJSON`](docs/api/screen#tojson), [`root`](docs/api/screen#root)
1314
- [Jest matchers](docs/api/jest-matchers) - validate assumptions about your UI
1415
- [User Event](docs/api/events/user-event) - simulate common user interactions like [`press`](docs/api/events/user-event#press) or [`type`](docs/api/events/user-event#type) in a realistic way
15-
- [Fire Event](docs/api/events/fire-event) - simulate any component event in a simplified way
16-
purposes
16+
- [Fire Event](docs/api/events/fire-event) - simulate any component event in a simplified way purposes
1717
- Misc APIs:
18-
- [`renderHook` function](docs/api/misc/render-hook) - render hooks for testing
18+
- [`renderHook` function](docs/api/misc/render-hook) - render hooks for testing
1919
- [Async utils](docs/api/misc/async): `findBy*` queries, `wait`, `waitForElementToBeRemoved`
2020
- [Configuration](docs/api/misc/config): `configure`, `resetToDefaults`
2121
- [Accessibility](docs/api/misc/accessibility): `isHiddenFromAccessibility`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["testing-env", "understanding-act"]
1+
["testing-env", "understanding-act", "third-party-integration"]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Third-Party Library Integration
2+
3+
The React Native Testing Library is designed to simulate the core behaviors of React Native. However, it does not replicate the internal logic of third-party libraries. This guide explains how to integrate your library with RNTL.
4+
5+
## Handling Events in Third-Party Libraries
6+
7+
RNTL provides two subsystems to simulate events:
8+
9+
- **Fire Event**: A lightweight simulation system that can trigger event handlers defined on both host and composite components.
10+
- **User Event**: A more realistic interaction simulation system that can trigger event handlers defined only on host components.
11+
12+
In many third-party libraries, event handling involves native code, which means RNTL cannot fully simulate the event flow, as it runs only JavaScript code. To address this limitation, you can use `testOnly_on*` props on host components to expose custom events to RNTL’s event subsystems. Both subsystems will first attempt to locate the standard `on*` event handlers; if these are not available, they fall back to the `testOnly_on*` handlers.
13+
14+
### Example: React Native Gesture Handler
15+
16+
React Native Gesture Handler (RNGH) provides a composite [Pressable](https://docs.swmansion.com/react-native-gesture-handler/docs/components/pressable/) component with `onPress*` props. These event handlers are not exposed on the rendered host views; instead, they are invoked via RNGH’s internal event flow, which involves native modules. As a result, they are not accessible to RNTL’s event subsystems.
17+
18+
To enable RNTL to interact with RNGH’s `Pressable` component, the library exposes `testOnly_onPress*` props on the `NativeButton` host component rendered by `Pressable`. This adjustment allows RNTL to simulate interactions during testing.
19+
20+
```tsx title="Simplified RNGH Pressable component"
21+
function Pressable({ onPress, onPressIn, onPressOut, onLongPress, ... }) {
22+
23+
// Component logic...
24+
25+
const isTestEnv = process.env.NODE_ENV === 'test';
26+
27+
return (
28+
<GestureDetector gesture={gesture}>
29+
<NativeButton
30+
/* Other props... */
31+
testOnly_onPress={isTestEnv ? onPress : undefined}
32+
testOnly_onPressIn={isTestEnv ? onPressIn : undefined}
33+
testOnly_onPressOut={isTestEnv ? onPressOut : undefined}
34+
testOnly_onLongPress={isTestEnv ? onLongPress : undefined}
35+
/>
36+
</GestureDetector>
37+
);
38+
}
39+
```

website/docs/13.x/docs/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
uri: /api
33
---
4+
45
# API Overview
56

67
React Native Testing Library consists of following APIs:
@@ -12,10 +13,9 @@ React Native Testing Library consists of following APIs:
1213
- Helpers: [`debug`](docs/api/screen#debug), [`toJSON`](docs/api/screen#tojson), [`root`](docs/api/screen#root)
1314
- [Jest matchers](docs/api/jest-matchers) - validate assumptions about your UI
1415
- [User Event](docs/api/events/user-event) - simulate common user interactions like [`press`](docs/api/events/user-event#press) or [`type`](docs/api/events/user-event#type) in a realistic way
15-
- [Fire Event](docs/api/events/fire-event) - simulate any component event in a simplified way
16-
purposes
16+
- [Fire Event](docs/api/events/fire-event) - simulate any component event in a simplified way purposes
1717
- Misc APIs:
18-
- [`renderHook` function](docs/api/misc/render-hook) - render hooks for testing
18+
- [`renderHook` function](docs/api/misc/render-hook) - render hooks for testing
1919
- [Async utils](docs/api/misc/async): `findBy*` queries, `wait`, `waitForElementToBeRemoved`
2020
- [Configuration](docs/api/misc/config): `configure`, `resetToDefaults`
2121
- [Accessibility](docs/api/misc/accessibility): `isHiddenFromAccessibility`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["how-to-query", "troubleshooting", "faq", "community-resources", "third-party-integration"]
1+
["how-to-query", "troubleshooting", "faq", "community-resources"]

website/docs/13.x/docs/guides/third-party-integration.mdx

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)