forked from gethomepage/homepage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.js
More file actions
38 lines (34 loc) · 1.54 KB
/
Copy pathvitest.setup.js
File metadata and controls
38 lines (34 loc) · 1.54 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
import "@testing-library/jest-dom/vitest";
import { cleanup } from "@testing-library/react";
import { afterEach, vi } from "vitest";
afterEach(() => {
// Node-environment tests shouldn't require jsdom; guard cleanup accordingly.
if (typeof document !== "undefined") cleanup();
});
// Avoid NextAuth client-side fetches during unit tests.
vi.mock("next-auth/react", () => ({
SessionProvider: ({ children }) => children ?? null,
getProviders: vi.fn(async () => ({})),
}));
// implement a couple of common formatters mocked in next-i18next
vi.mock("next-i18next/pages", () => ({
// Keep app/page components importable in unit tests.
appWithTranslation: (Component) => Component,
useTranslation: () => ({
i18n: { language: "en" },
t: (key, opts) => {
if (key === "common.number") return String(opts?.value ?? "");
if (key === "common.percent") return String(opts?.value ?? "");
if (key === "common.bytes") return String(opts?.value ?? "");
if (key === "common.bbytes") return String(opts?.value ?? "");
if (key === "common.byterate") return String(opts?.value ?? "");
if (key === "common.bibyterate") return String(opts?.value ?? "");
if (key === "common.bitrate") return String(opts?.value ?? "");
if (key === "common.duration") return String(opts?.value ?? "");
if (key === "common.ms") return String(opts?.value ?? "");
if (key === "common.date") return String(opts?.value ?? "");
if (key === "common.relativeDate") return String(opts?.value ?? "");
return key;
},
}),
}));