Files
ai_soc_sw/projects/P01_errlens_app/tests/setup.ts
T

43 lines
823 B
TypeScript
Raw Normal View History

// Jest 测试环境配置
import '@testing-library/jest-dom'
// Mock Taro API
jest.mock('@tarojs/taro', () => ({
getEnv: jest.fn(() => 'WEB'),
ENV_TYPE: {
WEAPP: 'WEAPP',
WEB: 'WEB',
RN: 'RN',
TT: 'TT'
},
request: jest.fn(),
uploadFile: jest.fn(),
downloadFile: jest.fn(),
createSelectorQuery: jest.fn(() => ({
select: jest.fn().mockReturnThis(),
boundingClientRect: jest.fn().mockReturnThis(),
exec: jest.fn(cb => cb([{}]))
})),
getSystemInfoSync: jest.fn(() => ({
windowWidth: 375,
windowHeight: 667
}))
}))
// Mock Network
jest.mock('../src/network', () => ({
Network: {
request: jest.fn(),
uploadFile: jest.fn(),
downloadFile: jest.fn()
}
}))
// 全局测试超时
jest.setTimeout(10000)
// 清理
afterEach(() => {
jest.clearAllMocks()
})