Files
expo-popcore-app/jest.setup.js
imeepos a1544ec85f fix: 修复 Jest 测试配置和 useCategories hook 实现
- 修复 jest.setup.js 中不存在的 NativeAnimatedHelper 模块引用
- 优化 jest.config.js 配置,分离 js 和 ts/tsx 的转换配置
- 添加 @testing-library/react 依赖
- 导出 useCategoriesStore 以供测试使用
- 修复 useCategories hook 的参数合并逻辑,确保 inputParams 正确覆盖默认参数
- 修复错误处理时 data 状态设置为 null
- 更新 CategoriesState 类型定义,允许 data 为 null

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-19 11:46:51 +08:00

86 lines
1.8 KiB
JavaScript

require('@testing-library/jest-native/extend-expect')
// Mock react-native modules
// Note: NativeAnimatedHelper may not be needed in newer React Native versions
// jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')
// Mock expo modules
jest.mock('expo-constants', () => ({
default: {},
}))
jest.mock('expo-linking', () => ({
createURL: (url) => url,
parse: (url) => ({ path: url }),
}))
jest.mock('expo-secure-store', () => ({
getItemAsync: jest.fn(),
setItemAsync: jest.fn(),
deleteItemAsync: jest.fn(),
}))
jest.mock('expo-font', () => ({
useFonts: () => [true, null],
}))
jest.mock('expo-splash-screen', () => ({
preventAutoHideAsync: jest.fn(),
hideAsync: jest.fn(),
}))
// Mock react-native-reanimated
jest.mock('react-native-reanimated', () => {
const Reanimated = require('react-native-reanimated/mock')
Reanimated.default.call = () => {}
return Reanimated
})
// Mock nativewind
jest.mock('nativewind', () => ({
styled: jest.fn(),
}))
// Mock @react-navigation/native
jest.mock('@react-navigation/native', () => ({
useNavigation: () => ({
navigate: jest.fn(),
goBack: jest.fn(),
reset: jest.fn(),
}),
useRoute: () => ({
params: {},
}),
NavigationContainer: ({ children }) => children,
}))
// Mock expo-router
jest.mock('expo-router', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
back: jest.fn(),
}),
useSegments: () => [],
usePathname: () => '/',
}))
// Global mock for console methods to reduce noise in tests
global.console = {
...console,
error: jest.fn(),
warn: jest.fn(),
log: jest.fn(),
}
// Mock @repo/core and @repo/sdk
jest.mock('@repo/core', () => ({
root: {
get: jest.fn(),
},
}))
jest.mock('@repo/sdk', () => ({
CategoryController: class MockCategoryController {},
}))