test: restore and fix tests broken by lazy-loading
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 4s
Build & Deploy / 🏗️ Build (push) Successful in 1m41s
Build & Deploy / 🧪 QA (push) Successful in 2m1s
Build & Deploy / 🚀 Deploy (push) Failing after 7s
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 4s
Build & Deploy / 🏗️ Build (push) Successful in 1m41s
Build & Deploy / 🧪 QA (push) Successful in 2m1s
Build & Deploy / 🚀 Deploy (push) Failing after 7s
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
This commit is contained in:
56
tests/setup.tsx
Normal file
56
tests/setup.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import React from "react";
|
||||
import { vi } from "vitest";
|
||||
|
||||
// Mock next/navigation
|
||||
vi.mock("next/navigation", () => ({
|
||||
usePathname: () => "/",
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
back: vi.fn(),
|
||||
}),
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
}));
|
||||
|
||||
// Mock next-intl to avoid transitive next/server issues
|
||||
vi.mock("next-intl/middleware", () => ({
|
||||
default: vi.fn(() => (req: any) => req),
|
||||
}));
|
||||
|
||||
vi.mock("next-intl/server", () => ({
|
||||
getRequestConfig: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock next/server
|
||||
vi.mock("next/server", () => ({
|
||||
NextResponse: {
|
||||
json: vi.fn(),
|
||||
next: vi.fn(),
|
||||
redirect: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock next/dynamic to be synchronous in tests
|
||||
vi.mock("next/dynamic", () => ({
|
||||
default: vi.fn((loader) => {
|
||||
return (props: any) => {
|
||||
const [Component, setComponent] = React.useState<any>(null);
|
||||
React.useEffect(() => {
|
||||
loader().then((mod: any) => {
|
||||
setComponent(
|
||||
() =>
|
||||
mod.default ||
|
||||
mod.PortfolioSection ||
|
||||
mod.ExpertiseSection ||
|
||||
mod.TechnicalSpecsSection ||
|
||||
mod.CTASection ||
|
||||
mod,
|
||||
);
|
||||
});
|
||||
}, []);
|
||||
return Component ? <Component {...props} /> : null;
|
||||
};
|
||||
}),
|
||||
}));
|
||||
Reference in New Issue
Block a user