-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
56 lines (50 loc) · 1.25 KB
/
vitest.setup.ts
File metadata and controls
56 lines (50 loc) · 1.25 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as matchers from "@testing-library/jest-dom/matchers";
import React from "react";
import { expect, vi } from "vitest";
// Make React available globally for JSX
global.React = React;
// Extend vitest's expect with jest-dom matchers
expect.extend(matchers);
// Mock window.gtag for analytics
Object.defineProperty(window, "gtag", {
value: vi.fn(),
writable: true,
});
// Mock Next.js Image component
vi.mock("next/image", () => ({
default: ({
src,
alt,
...props
}: {
src: string;
alt: string;
[key: string]: unknown;
}) => {
return React.createElement("img", { src, alt, ...props });
},
}));
// Mock Next.js Head component
vi.mock("next/head", () => ({
default: ({ children }: { children: React.ReactNode }) => children,
}));
// Mock Next.js Link component
vi.mock("next/link", () => ({
default: ({
children,
href,
...props
}: {
children: React.ReactNode;
href:
| string
| { pathname?: string; query?: Record<string, unknown>; hash?: string };
[key: string]: unknown;
}) => {
const hrefStr =
typeof href === "string"
? href
: (href?.pathname ?? "" + (href?.hash ?? ""));
return React.createElement("a", { href: hrefStr, ...props }, children);
},
}));