fix: bug
This commit is contained in:
117
jest.setup.js
117
jest.setup.js
@@ -3,95 +3,8 @@ jest.mock('react-native-css-interop', () => ({
|
||||
__esModule: true,
|
||||
}))
|
||||
|
||||
// Mock react-native BEFORE any other imports to avoid flow type issues
|
||||
jest.mock('react-native', () => {
|
||||
const mockReact = require('react')
|
||||
|
||||
// Helper to create mock components that render as actual React elements
|
||||
const mockCreateMockComponent = (mockName) => {
|
||||
const MockComponent = mockReact.forwardRef(({ children, ...mockProps }, mockRef) => {
|
||||
return mockReact.createElement(mockName, { ...mockProps, ref: mockRef }, children)
|
||||
})
|
||||
MockComponent.displayName = mockName
|
||||
return MockComponent
|
||||
}
|
||||
|
||||
// Create Pressable with onPress support
|
||||
const MockPressable = mockReact.forwardRef(({ children, onPress, ...mockProps }, mockRef) => {
|
||||
return mockReact.createElement('Pressable', { ...mockProps, ref: mockRef, onPress, onClick: onPress }, children)
|
||||
})
|
||||
MockPressable.displayName = 'Pressable'
|
||||
|
||||
// Create TouchableOpacity with onPress support
|
||||
const MockTouchableOpacity = mockReact.forwardRef(({ children, onPress, ...mockProps }, mockRef) => {
|
||||
return mockReact.createElement('TouchableOpacity', { ...mockProps, ref: mockRef, onPress, onClick: onPress }, children)
|
||||
})
|
||||
MockTouchableOpacity.displayName = 'TouchableOpacity'
|
||||
|
||||
return {
|
||||
RefreshControl: mockCreateMockComponent('RefreshControl'),
|
||||
ScrollView: mockCreateMockComponent('ScrollView'),
|
||||
FlatList: mockCreateMockComponent('FlatList'),
|
||||
View: mockCreateMockComponent('View'),
|
||||
Text: mockCreateMockComponent('Text'),
|
||||
Image: mockCreateMockComponent('Image'),
|
||||
Pressable: MockPressable,
|
||||
TouchableOpacity: MockTouchableOpacity,
|
||||
TextInput: mockCreateMockComponent('TextInput'),
|
||||
ActivityIndicator: mockCreateMockComponent('ActivityIndicator'),
|
||||
Platform: {
|
||||
OS: 'web',
|
||||
select: (mockObj) => mockObj.web || mockObj.default,
|
||||
},
|
||||
Animated: {
|
||||
View: mockCreateMockComponent('Animated.View'),
|
||||
Text: mockCreateMockComponent('Animated.Text'),
|
||||
Image: mockCreateMockComponent('Animated.Image'),
|
||||
Value: class MockValue {
|
||||
constructor(mockV) { this._value = mockV }
|
||||
setValue(mockV) { this._value = mockV }
|
||||
__getValue() { return this._value }
|
||||
interpolate() { return this }
|
||||
},
|
||||
timing: () => ({ start: jest.fn() }),
|
||||
spring: () => ({ start: jest.fn() }),
|
||||
event: () => jest.fn(),
|
||||
},
|
||||
PanResponder: {
|
||||
create: () => ({ panHandlers: {} }),
|
||||
},
|
||||
StyleSheet: { create: (mockStyles) => mockStyles },
|
||||
Dimensions: { get: () => ({ width: 375, height: 812 }) },
|
||||
StatusBar: mockCreateMockComponent('StatusBar'),
|
||||
SafeAreaView: mockCreateMockComponent('SafeAreaView'),
|
||||
useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
||||
NativeModules: {
|
||||
DevMenu: {},
|
||||
SettingsManager: {},
|
||||
},
|
||||
Settings: {
|
||||
get: jest.fn(),
|
||||
set: jest.fn(),
|
||||
},
|
||||
Alert: {
|
||||
alert: jest.fn(),
|
||||
},
|
||||
Linking: {
|
||||
openURL: jest.fn(),
|
||||
},
|
||||
Appearance: {
|
||||
getColorScheme: jest.fn(() => 'light'),
|
||||
addChangeListener: jest.fn(),
|
||||
removeChangeListener: jest.fn(),
|
||||
},
|
||||
BackHandler: {
|
||||
addEventListener: jest.fn(() => ({ remove: jest.fn() })),
|
||||
removeEventListener: jest.fn(),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
require('@testing-library/jest-native/extend-expect')
|
||||
// Import extend-expect for jest matchers
|
||||
import '@testing-library/react-native/extend-expect'
|
||||
|
||||
// Mock global Appearance for react-native-css-interop
|
||||
global.Appearance = {
|
||||
@@ -168,9 +81,20 @@ jest.mock('react-native-safe-area-context', () => ({
|
||||
|
||||
// Mock react-native-gesture-handler
|
||||
jest.mock('react-native-gesture-handler', () => {
|
||||
const { View } = require('react-native')
|
||||
const mockReact = require('react')
|
||||
const mockRN = require('react-native')
|
||||
|
||||
// Mock Swipeable component that renders children and right actions
|
||||
const MockSwipeable = mockReact.forwardRef(({ children, renderRightActions, testID, enabled, ...props }, ref) => {
|
||||
return mockReact.createElement(mockRN.View, { testID, ref, ...props }, [
|
||||
children,
|
||||
renderRightActions && renderRightActions(),
|
||||
])
|
||||
})
|
||||
MockSwipeable.displayName = 'Swipeable'
|
||||
|
||||
return {
|
||||
GestureDetector: View,
|
||||
GestureDetector: mockRN.View,
|
||||
Gesture: {
|
||||
Tap: () => ({}),
|
||||
Pan: () => ({}),
|
||||
@@ -182,11 +106,12 @@ jest.mock('react-native-gesture-handler', () => {
|
||||
ForceTouch: () => ({}),
|
||||
ManualGesture: () => ({}),
|
||||
},
|
||||
GestureHandlerRootView: View,
|
||||
RawButton: View,
|
||||
BaseButton: View,
|
||||
RectButton: View,
|
||||
BorderlessButton: View,
|
||||
GestureHandlerRootView: mockRN.View,
|
||||
RawButton: mockRN.View,
|
||||
BaseButton: mockRN.View,
|
||||
RectButton: mockRN.View,
|
||||
BorderlessButton: mockRN.View,
|
||||
Swipeable: MockSwipeable,
|
||||
State: {},
|
||||
Directions: {},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user