forked from int-money/landing-page
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.tsx
More file actions
40 lines (35 loc) · 1.05 KB
/
Copy pathvitest.setup.tsx
File metadata and controls
40 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import "@testing-library/jest-dom/vitest";
import { vi } from "vitest";
// jsdom does not implement scrollTo
Element.prototype.scrollTo = vi.fn();
// Mock next/image
vi.mock("next/image", () => ({
__esModule: true,
default: (props: Record<string, unknown>) => {
const { fill, priority, ...rest } = props as Record<string, unknown>;
void fill;
void priority;
// eslint-disable-next-line @next/next/no-img-element
return <img {...(rest as React.ImgHTMLAttributes<HTMLImageElement>)} />;
},
}));
// Mock next/navigation
vi.mock("next/navigation", () => ({
useRouter: () => ({
push: vi.fn(),
replace: vi.fn(),
prefetch: vi.fn(),
back: vi.fn(),
}),
useSearchParams: () => new URLSearchParams(),
usePathname: () => "/",
}));
// Mock next-themes
vi.mock("next-themes", () => ({
ThemeProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
useTheme: () => ({ theme: "dark", setTheme: vi.fn() }),
}));
// Mock @vercel/analytics
vi.mock("@vercel/analytics/next", () => ({
Analytics: () => null,
}));