| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /**
- * Jest setup file for cfc-frontend mini-program tests.
- * Mocks the global `uni` API and other mini-program runtime globals.
- */
- // ---- Mock uni global ----
- global.uni = {
- // Storage mocks
- _storage: {},
- getStorageSync(key) {
- return this._storage[key] !== undefined ? this._storage[key] : ''
- },
- setStorageSync(key, value) {
- this._storage[key] = value
- },
- removeStorageSync(key) {
- delete this._storage[key]
- },
- // Request mock (override in individual tests)
- request: jest.fn(),
- // Toast mock
- showToast: jest.fn(),
- // Navigation mocks
- navigateTo: jest.fn(),
- redirectTo: jest.fn(),
- reLaunch: jest.fn(),
- switchTab: jest.fn(),
- navigateBack: jest.fn(),
- // Account info mock (set in tests as needed)
- getAccountInfoSync: jest.fn(() => ({
- miniProgram: { envVersion: 'develop' }
- })),
- // Other common uni APIs
- showLoading: jest.fn(),
- hideLoading: jest.fn(),
- showModal: jest.fn(),
- login: jest.fn(),
- getUserProfile: jest.fn(),
- getUserInfo: jest.fn(),
- getSystemInfoSync: jest.fn(() => ({
- platform: 'devtools',
- language: 'zh_CN',
- version: '8.0.0'
- }))
- }
- // ---- Mock Vue ----
- jest.mock('vue', () => {
- const Vue = jest.requireActual('vue')
- Vue.config.productionTip = false
- return Vue
- })
|