Files
evig/jest.setup.js
T
g-butandClaude Opus 4.6 4eb6d4ec35 fix: audit report update, repairer approval refactor, test fixes
- Update codebase audit report with latest findings
- Refactor repairer application approval route to Drizzle ORM
- Fix marketplace page and ReviewForm minor issues
- Fix rate-limiter test flakiness with timer mocks
- Update jest.setup.js for test stability

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 14:22:59 +01:00

87 lines
1.8 KiB
JavaScript

import { TextEncoder, TextDecoder } from 'util'
import '@testing-library/jest-dom'
// Polyfill TextEncoder/TextDecoder for jsdom environment (needed by pg/Drizzle)
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
// Mock Next.js router
jest.mock('next/router', () => ({
useRouter() {
return {
route: '/',
pathname: '/',
query: '',
asPath: '/',
push: jest.fn(),
pop: jest.fn(),
reload: jest.fn(),
back: jest.fn(),
prefetch: jest.fn().mockResolvedValue(undefined),
beforePopState: jest.fn(),
events: {
on: jest.fn(),
off: jest.fn(),
emit: jest.fn(),
},
}
},
}))
// Mock next-auth
jest.mock('next-auth/react', () => ({
useSession: jest.fn(() => ({
data: null,
status: 'unauthenticated',
})),
signIn: jest.fn(),
signOut: jest.fn(),
getSession: jest.fn(),
}))
// Mock next-auth (server-side)
jest.mock('next-auth', () => ({
auth: jest.fn(() => Promise.resolve(null)),
}))
// Mock fetch
global.fetch = jest.fn()
// Browser-only mocks (skip in node environment for API route tests)
if (typeof window !== 'undefined') {
// Mock window.matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
})
// Mock IntersectionObserver
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
observe() {
return null
}
disconnect() {
return null
}
unobserve() {
return null
}
}
}