mirror of
https://github.com/johndoe6345789/snippet-pastebin.git
synced 2026-04-24 13:34:55 +00:00
- Install Jest, @testing-library/react, and related dependencies - Create jest.config.ts and jest.setup.ts configuration - Generate unit tests for all 141 React components (1 per component) - Tests cover UI components, app pages, features, and utilities - 232 tests currently passing with proper assertions - Add test scripts for running unit tests (npm test) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
import '@testing-library/jest-dom'
|
|
import React from 'react'
|
|
|
|
// Make React globally available for components that may reference it
|
|
global.React = React
|
|
|
|
// Mock Next.js router
|
|
jest.mock('next/router', () => ({
|
|
useRouter: () => ({
|
|
push: jest.fn(),
|
|
pathname: '/',
|
|
query: {},
|
|
asPath: '/',
|
|
}),
|
|
}))
|
|
|
|
// Mock Next.js navigation
|
|
jest.mock('next/navigation', () => ({
|
|
useRouter: () => ({
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
prefetch: jest.fn(),
|
|
}),
|
|
usePathname: () => '/',
|
|
useSearchParams: () => new URLSearchParams(),
|
|
useParams: () => ({}),
|
|
}))
|
|
|
|
// Mock window.matchMedia
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: jest.fn().mockImplementation(query => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
})),
|
|
})
|
|
|
|
// Suppress console errors in tests unless explicitly needed
|
|
const originalError = console.error
|
|
beforeAll(() => {
|
|
console.error = (...args: any[]) => {
|
|
if (
|
|
typeof args[0] === 'string' &&
|
|
(args[0].includes('Warning: ReactDOM.render') ||
|
|
args[0].includes('Warning: useLayoutEffect') ||
|
|
args[0].includes('Not implemented: HTMLFormElement.prototype.submit'))
|
|
) {
|
|
return
|
|
}
|
|
originalError.call(console, ...args)
|
|
}
|
|
})
|
|
|
|
afterAll(() => {
|
|
console.error = originalError
|
|
})
|