@@ -35,23 +35,47 @@ jest.mock('expo-audio', () => ({
3535} ) ) ;
3636
3737// Mock the host component names function to prevent testing library errors
38- jest . mock ( '@testing-library/react-native/build/helpers/host-component-names' , ( ) => ( {
39- getHostComponentNames : jest . fn ( ( ) => ( {
40- text : 'Text' ,
41- view : 'View' ,
42- scrollView : 'ScrollView' ,
43- touchable : 'TouchableOpacity' ,
44- switch : 'Switch' ,
45- textInput : 'TextInput' ,
46- } ) ) ,
47- configureHostComponentNamesIfNeeded : jest . fn ( ) ,
48- isHostText : jest . fn ( ( element ) => element ?. type === 'Text' || element ?. _fiber ?. type === 'Text' || ( typeof element === 'object' && element ?. props ?. children && typeof element . props . children === 'string' ) ) ,
49- isHostTextInput : jest . fn ( ( element ) => element ?. type === 'TextInput' || element ?. _fiber ?. type === 'TextInput' ) ,
50- isHostImage : jest . fn ( ( element ) => element ?. type === 'Image' || element ?. _fiber ?. type === 'Image' ) ,
51- isHostSwitch : jest . fn ( ( element ) => element ?. type === 'Switch' || element ?. _fiber ?. type === 'Switch' ) ,
52- isHostScrollView : jest . fn ( ( element ) => element ?. type === 'ScrollView' || element ?. _fiber ?. type === 'ScrollView' ) ,
53- isHostModal : jest . fn ( ( element ) => element ?. type === 'Modal' || element ?. _fiber ?. type === 'Modal' ) ,
54- } ) ) ;
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+ }
5579
5680// Global mocks for common problematic modules
5781jest . mock ( '@notifee/react-native' , ( ) => {
0 commit comments