Skip to content

Commit 494562a

Browse files
committed
Fix tests
1 parent 415ef9b commit 494562a

22 files changed

+23002
-155
lines changed

example/App.tsx

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { StyleSheet, View, Text, TouchableOpacity, Alert, Platform, Dimensions } from 'react-native';
22
import { StatusBar } from 'expo-status-bar';
3+
4+
// TEST: This log should show up immediately when the app starts
5+
console.log('🧪 [TEST] App.tsx loaded - Console.log is working!');
6+
7+
console.log('🧪 [TEST] About to import cloudinary-react-native...');
38
import {AdvancedImage, AdvancedVideo} from 'cloudinary-react-native';
9+
console.log('🧪 [TEST] Successfully imported cloudinary-react-native!', {AdvancedVideo: typeof AdvancedVideo});
410
import {Cloudinary} from '@cloudinary/url-gen';
511
import {scale} from "@cloudinary/url-gen/actions/resize";
612
import {cartoonify} from "@cloudinary/url-gen/actions/effect";
@@ -29,6 +35,9 @@ const cld = new Cloudinary({
2935
});
3036

3137
export default function App() {
38+
// TEST: This should show when the App component is created
39+
console.log('🧪 [TEST] App component function called!');
40+
3241
const videoPlayer = useRef<any>(null);
3342
const [analyticsEnabled, setAnalyticsEnabled] = useState(false);
3443
const [autoTracking, setAutoTracking] = useState(false);
@@ -158,22 +167,27 @@ export default function App() {
158167
</View>
159168

160169
<View style={styles.videoContainer}>
161-
<AdvancedVideo
162-
ref={videoPlayer}
163-
videoStyle={styles.video}
164-
cldVideo={createMyVideoObject()}
165-
enableAnalytics={analyticsEnabled}
166-
autoTrackAnalytics={autoTracking}
167-
analyticsOptions={{
168-
customData: {
169-
userId: 'demo-user-123',
170-
appVersion: '1.0.0',
171-
platform: 'react-native'
172-
},
173-
videoPlayerType: 'auto-detected',
174-
videoPlayerVersion: 'auto-detected'
175-
}}
176-
/>
170+
{(() => {
171+
console.log('🧪 [TEST] About to render AdvancedVideo component...');
172+
return (
173+
<AdvancedVideo
174+
ref={videoPlayer}
175+
videoStyle={styles.video}
176+
cldVideo={createMyVideoObject()}
177+
enableAnalytics={analyticsEnabled}
178+
autoTrackAnalytics={autoTracking}
179+
analyticsOptions={{
180+
customData: {
181+
userId: 'demo-user-123',
182+
appVersion: '1.0.0',
183+
platform: 'react-native'
184+
},
185+
videoPlayerType: 'auto-detected',
186+
videoPlayerVersion: 'auto-detected'
187+
}}
188+
/>
189+
);
190+
})()}
177191
</View>
178192

179193
<View style={styles.statusContainer}>

jest-setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Set test environment
2+
process.env.NODE_ENV = 'test';

jest.setup-before-env.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This file runs before Jest environment is set up
2+
// Mock React Native components globally before any imports
3+
4+
// Set NODE_ENV early
5+
process.env.NODE_ENV = 'test';
6+
7+
// Mock React Native entirely
8+
jest.doMock('react-native', () => {
9+
const React = require('react');
10+
11+
// Create mock components that work with React Native Testing Library
12+
const mockComponent = (name) => {
13+
const Component = React.forwardRef((props, ref) => {
14+
return React.createElement(name, { ...props, ref });
15+
});
16+
Component.displayName = name;
17+
return Component;
18+
};
19+
20+
return {
21+
Platform: {
22+
OS: 'ios',
23+
select: jest.fn(options => options.ios),
24+
},
25+
Dimensions: {
26+
get: jest.fn(() => ({ width: 375, height: 667 })),
27+
},
28+
View: mockComponent('View'),
29+
Text: mockComponent('Text'),
30+
Image: mockComponent('Image'),
31+
TouchableOpacity: mockComponent('TouchableOpacity'),
32+
ScrollView: mockComponent('ScrollView'),
33+
StyleSheet: {
34+
create: jest.fn(styles => styles),
35+
},
36+
Alert: {
37+
alert: jest.fn(),
38+
},
39+
Animated: {
40+
View: mockComponent('Animated.View'),
41+
timing: jest.fn(() => ({
42+
start: jest.fn(),
43+
})),
44+
Value: jest.fn(() => ({
45+
setValue: jest.fn(),
46+
addListener: jest.fn(),
47+
removeListener: jest.fn(),
48+
})),
49+
},
50+
Easing: {
51+
linear: jest.fn(),
52+
ease: jest.fn(),
53+
quad: jest.fn(),
54+
},
55+
};
56+
});

mocks/expo-av-mock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Mock expo-av for Jest tests - but make it NOT available for adapter tests
2+
module.exports = {};

mocks/expo-constants-mock.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mock expo-constants for Jest tests
2+
module.exports = {
3+
default: {},
4+
};

mocks/expo-crypto-mock.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mock expo-crypto for Jest tests
2+
module.exports = {
3+
default: {},
4+
};

mocks/expo-video-mock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Mock expo-video for Jest tests - but make it NOT available for adapter tests
2+
module.exports = {};

mocks/react-native-mock.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const React = require('react');
2+
3+
// Create proper React components for testing
4+
const MockView = React.forwardRef((props, ref) => React.createElement('View', { ...props, ref }));
5+
const MockText = React.forwardRef((props, ref) => React.createElement('Text', { ...props, ref }));
6+
const MockImage = React.forwardRef((props, ref) => React.createElement('Image', { ...props, ref }));
7+
const MockTouchableOpacity = React.forwardRef((props, ref) => React.createElement('TouchableOpacity', { ...props, ref }));
8+
9+
// Mock React Native for Jest tests
10+
const mockReactNative = {
11+
Platform: {
12+
OS: 'ios',
13+
select: jest.fn(options => options.ios),
14+
},
15+
Dimensions: {
16+
get: jest.fn(() => ({ width: 375, height: 667 })),
17+
},
18+
View: MockView,
19+
Text: MockText,
20+
Image: MockImage,
21+
TouchableOpacity: MockTouchableOpacity,
22+
StyleSheet: {
23+
create: jest.fn(styles => styles),
24+
},
25+
Alert: {
26+
alert: jest.fn(),
27+
},
28+
Animated: {
29+
View: MockView,
30+
timing: jest.fn(() => ({
31+
start: jest.fn(),
32+
})),
33+
Value: jest.fn(() => ({
34+
setValue: jest.fn(),
35+
addListener: jest.fn(),
36+
removeListener: jest.fn(),
37+
})),
38+
},
39+
Easing: {
40+
linear: jest.fn(),
41+
ease: jest.fn(),
42+
quad: jest.fn(),
43+
},
44+
};
45+
46+
module.exports = mockReactNative;

0 commit comments

Comments
 (0)