@@ -34,11 +34,48 @@ jest.mock('expo-audio', () => ({
3434 setIsAudioActiveAsync : jest . fn ( ) ,
3535} ) ) ;
3636
37- // Mock Platform.OS for React Native
38- jest . mock ( 'react-native/Libraries/Utilities/Platform' , ( ) => ( {
39- OS : 'ios' ,
40- select : jest . fn ( ) . mockImplementation ( ( obj ) => obj . ios || obj . default ) ,
41- } ) ) ;
37+ // Mock the host component names function to prevent testing library errors
38+ // Check if the internal module exists (for pre-v13 compatibility)
39+ try {
40+ require . resolve ( '@testing-library/react-native/build/helpers/host-component-names' ) ;
41+ // If the internal module exists, mock it (pre-v13)
42+ jest . mock ( '@testing-library/react-native/build/helpers/host-component-names' , ( ) => ( {
43+ getHostComponentNames : jest . fn ( ( ) => ( {
44+ text : 'Text' ,
45+ view : 'View' ,
46+ scrollView : 'ScrollView' ,
47+ touchable : 'TouchableOpacity' ,
48+ switch : 'Switch' ,
49+ textInput : 'TextInput' ,
50+ } ) ) ,
51+ configureHostComponentNamesIfNeeded : jest . fn ( ) ,
52+ isHostText : jest . fn ( ( element ) => element ?. type === 'Text' || element ?. _fiber ?. type === 'Text' || ( typeof element === 'object' && element ?. props ?. children && typeof element . props . children === 'string' ) ) ,
53+ isHostTextInput : jest . fn ( ( element ) => element ?. type === 'TextInput' || element ?. _fiber ?. type === 'TextInput' ) ,
54+ isHostImage : jest . fn ( ( element ) => element ?. type === 'Image' || element ?. _fiber ?. type === 'Image' ) ,
55+ isHostSwitch : jest . fn ( ( element ) => element ?. type === 'Switch' || element ?. _fiber ?. type === 'Switch' ) ,
56+ isHostScrollView : jest . fn ( ( element ) => element ?. type === 'ScrollView' || element ?. _fiber ?. type === 'ScrollView' ) ,
57+ isHostModal : jest . fn ( ( element ) => element ?. type === 'Modal' || element ?. _fiber ?. type === 'Modal' ) ,
58+ } ) ) ;
59+ } catch ( error ) {
60+ // Module doesn't exist (v13+), try to use the public API if available
61+ try {
62+ const { configureHostComponentNames } = require ( '@testing-library/react-native' ) ;
63+ // Configure host component names using the public API (v13+)
64+ if ( configureHostComponentNames ) {
65+ configureHostComponentNames ( {
66+ text : 'Text' ,
67+ view : 'View' ,
68+ scrollView : 'ScrollView' ,
69+ touchable : 'TouchableOpacity' ,
70+ switch : 'Switch' ,
71+ textInput : 'TextInput' ,
72+ } ) ;
73+ }
74+ } catch ( publicApiError ) {
75+ // If neither internal nor public API is available, log a warning but continue
76+ console . warn ( 'Unable to configure host component names for @testing-library/react-native. Tests may fail if they rely on component type detection.' ) ;
77+ }
78+ }
4279
4380// Global mocks for common problematic modules
4481jest . mock ( '@notifee/react-native' , ( ) => {
0 commit comments