freshyo/apps/admin-ui/tests/setup.ts
2026-10-20 11:19:25 +05:30

40 lines
1.3 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Global test environment for apps/admin-ui.
*
* Native / platform modules are redirected to shared shims through
* `jest.config.js#moduleNameMapper`; this file only installs process-wide
* globals that every suite needs.
*/
import { configure } from '@testing-library/react-native'
import { installTrpcNetworkMock } from './mocks/trpc-client'
// The real tRPC client + React Query settle over several ticks. Under the full
// parallel suite a 1s `waitFor` budget is too tight, so give async utils 5s.
configure({ asyncUtilTimeout: 5000 })
// The REAL tRPC client runs in tests; only the network response is faked.
installTrpcNetworkMock()
// Silence noisy console output that the app logs during render.
const IGNORED_CONSOLE = [
/\[admin-ui\]/,
/Failed to save push token/,
/force logout event received/,
]
const originalConsoleError = console.error
console.error = (...args: any[]) => {
const message = String(args[0] ?? '')
if (IGNORED_CONSOLE.some((pattern) => pattern.test(message))) return
originalConsoleError(...args)
}
console.log = jest.fn()
console.warn = jest.fn()
// React 19 + testing-library act() environment.
;(global as any).IS_REACT_ACT_ENVIRONMENT = true
afterEach(() => {
jest.clearAllTimers()
})