1
1
# Third-Party Library Integration
2
2
3
- React Native Testing Library (RNTL) is designed to simulate core React Native behaviors.
3
+ React Native Testing Library is designed to simulate core React Native behaviors.
4
4
However, it does not replicate the internal logic of third-party libraries. This guide
5
5
explains how to integrate your library with RNTL.
6
6
@@ -17,30 +17,32 @@ to expose custom events to RNTL's event subsystems. Both subsystems will first a
17
17
18
18
### Example: React Native Gesture Handler
19
19
20
- React Native Gesture Handler (RNGH) provides a composite ` Pressable ` component with ` onPress ` props.
20
+ React Native Gesture Handler (RNGH) provides a composite [ Pressable] ( https://docs.swmansion.com/react-native-gesture-handler/docs/components/pressable/ )
21
+ component with ` onPressXxx ` props.
21
22
These props are part of the library's internal event flow, which involves native modules and
22
23
` EventEmitters ` . As a result, they are not directly exposed to the host components rendered by
23
24
` Pressable ` , making them inaccessible to RNTL's event subsystems.
24
25
25
- To enable RNTL to interact with RNGH's ` Pressable ` component, the library exposes ` testOnly_onPress `
26
+ To enable RNTL to interact with RNGH's ` Pressable ` component, the library exposes ` testOnly_onPressXxx `
26
27
props on the ` NativeButton ` host component rendered by ` Pressable ` . This allows RNTL to simulate
27
28
interactions during testing.
28
29
29
30
``` tsx title="Simplified RNGH Pressable component"
30
31
function Pressable({ onPress , onPressIn , onPressOut , ... }) {
31
- // Component logic...
32
-
33
- const isTestEnv = process .env .NODE_ENV === ' test' ;
34
-
35
- return (
36
- <GestureDetector gesture = { gesture } >
37
- <NativeButton
38
- { /* Other props... */ }
39
- testOnly_onPress = { isTestEnv ? onPress : undefined }
40
- testOnly_onPressIn = { isTestEnv ? onPressIn : undefined }
41
- testOnly_onPressOut = { isTestEnv ? onPressOut : undefined }
42
- />
32
+
33
+ // Component logic...
34
+
35
+ const isTestEnv = process .env .NODE_ENV === ' test' ;
36
+
37
+ return (
38
+ <GestureDetector gesture = { gesture } >
39
+ <NativeButton
40
+ { /* Other props... */ }
41
+ testOnly_onPress = { isTestEnv ? onPress : undefined }
42
+ testOnly_onPressIn = { isTestEnv ? onPressIn : undefined }
43
+ testOnly_onPressOut = { isTestEnv ? onPressOut : undefined }
44
+ />
43
45
</GestureDetector >
44
- );
46
+ );
45
47
}
46
48
```
0 commit comments