feat: 添加测试框架和优化项目结构
- 添加 Jest 配置和测试设置 - 添加 use-categories hook 的单元测试 - 更新 CLAUDE.md 添加包管理工具说明 - 优化首页、视频页和频道页的组件结构 - 添加 .claude 命令配置文件 - 移除 bun.lock 和 package-lock.json,统一使用 bun - 更新 package.json 依赖 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
84
jest.setup.js
Normal file
84
jest.setup.js
Normal file
@@ -0,0 +1,84 @@
|
||||
import '@testing-library/jest-native/extend-expect'
|
||||
|
||||
// Mock react-native modules
|
||||
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 {},
|
||||
}))
|
||||
Reference in New Issue
Block a user