Set up Vitest for unit/integration tests and Playwright for E2E tests; add configs, tests, and documentation Co-authored-by: Moheeb Zara <[email protected]>
47 lines
987 B
TypeScript
47 lines
987 B
TypeScript
import '@testing-library/jest-dom'
|
|
import { expect, afterEach, vi } from 'vitest'
|
|
import { cleanup } from '@testing-library/react'
|
|
|
|
// Cleanup after each test
|
|
afterEach(() => {
|
|
cleanup()
|
|
})
|
|
|
|
// Mock next/navigation
|
|
vi.mock('next/navigation', () => ({
|
|
useRouter: () => ({
|
|
push: vi.fn(),
|
|
replace: vi.fn(),
|
|
prefetch: vi.fn(),
|
|
back: vi.fn(),
|
|
}),
|
|
usePathname: () => '/dashboard',
|
|
useSearchParams: () => new URLSearchParams(),
|
|
}))
|
|
|
|
// Mock next/image
|
|
vi.mock('next/image', () => ({
|
|
default: (props: any) => {
|
|
// eslint-disable-next-line jsx-a11y/alt-text
|
|
return <img {...props} />
|
|
},
|
|
}))
|
|
|
|
// Suppress console errors in tests (optional)
|
|
const originalError = console.error
|
|
beforeAll(() => {
|
|
console.error = (...args: any[]) => {
|
|
if (
|
|
typeof args[0] === 'string' &&
|
|
args[0].includes('Warning: ReactDOM.render')
|
|
) {
|
|
return
|
|
}
|
|
originalError.call(console, ...args)
|
|
}
|
|
})
|
|
|
|
afterAll(() => {
|
|
console.error = originalError
|
|
})
|