Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / apps/web/jest.setup.tsx |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | apps/web/jest.setup.tsx |
| Original SHA-256 | 36d1d84e71fb4da8c65ab4180e531e330b7fadf50c76edf82a9f196557756ebc |
| Git blob SHA | 5539aad76f9656e3dd2e09d8ccaaed5622e03114 |
| Reading-copy SHA-256 | 36d1d84e71fb4da8c65ab4180e531e330b7fadf50c76edf82a9f196557756ebc |
Recovered source transcript
Download complete source text ↓123 lines · 2.7 KB
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom'
import React from 'react'
// Mock Next.js router
jest.mock('next/router', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
pathname: '/',
query: {},
asPath: '/',
events: {
on: jest.fn(),
off: jest.fn(),
emit: jest.fn()
}
})
}))
// Mock next/navigation
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
back: jest.fn(),
forward: jest.fn(),
refresh: jest.fn(),
prefetch: jest.fn()
}),
usePathname: () => '/',
useSearchParams: () => new URLSearchParams(),
useParams: () => ({})
}))
// Mock Sentry
jest.mock('@sentry/nextjs', () => ({
init: jest.fn(),
captureException: jest.fn(),
captureMessage: jest.fn(),
withScope: jest.fn(),
Integrations: {
BrowserTracing: jest.fn()
}
}))
// Mock logging package
jest.mock('@thedaviddias/logging', () => ({
logger: {
error: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
debug: jest.fn()
}
}))
// Mock observability package
jest.mock('@thedaviddias/observability', () => ({
captureError: jest.fn(),
captureMessage: jest.fn(),
withScope: jest.fn()
}))
// Mock lucide-react icons
jest.mock('lucide-react', () => ({
ChevronDown: () => null,
ChevronUp: () => null,
Check: () => null,
ChevronsUpDown: () => null
}))
// Mock sonner toast
jest.mock('sonner', () => ({
Toaster: () => null,
toast: {
success: jest.fn(),
error: jest.fn(),
warning: jest.fn()
}
}))
// Suppress console errors during tests
const originalConsoleError = console.error
console.error = (...args) => {
// Suppress specific errors that might occur during testing
const suppressedErrors = [
'Warning: ReactDOM.render is no longer supported',
'Warning: useLayoutEffect does nothing on the server'
]
if (!suppressedErrors.some(error => args[0]?.includes(error))) {
originalConsoleError(...args)
}
}
// Reset mocks after each test
afterEach(() => {
jest.clearAllMocks()
})
// Mock PointerEvent for Radix UI components
function createMockPointerEvent(type: string, props: PointerEventInit = {}): PointerEvent {
const event = new Event(type, props) as PointerEvent
Object.assign(event, {
button: props.button ?? 0,
ctrlKey: props.ctrlKey ?? false,
pointerType: props.pointerType ?? 'mouse'
})
return event
}
// Assign the mock function to the global window object
window.PointerEvent = createMockPointerEvent as any
// Mock HTMLElement methods needed for Radix UI
Object.assign(window.HTMLElement.prototype, {
scrollIntoView: jest.fn(),
releasePointerCapture: jest.fn(),
hasPointerCapture: jest.fn()
})