mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-18 21:44:06 +01:00
fix error page test
This commit is contained in:
parent
8a65012044
commit
aff0bad8bb
@ -5,6 +5,8 @@ import Error from "@/app/error";
|
|||||||
import Loading from "@/app/loading";
|
import Loading from "@/app/loading";
|
||||||
import NotFound from "@/app/not-found";
|
import NotFound from "@/app/not-found";
|
||||||
|
|
||||||
|
import { mockError, mockReset } from "./utils";
|
||||||
|
|
||||||
// Mock Cookies
|
// Mock Cookies
|
||||||
jest.mock("next/headers", () => ({
|
jest.mock("next/headers", () => ({
|
||||||
cookies: jest.fn(() => ({
|
cookies: jest.fn(() => ({
|
||||||
@ -15,15 +17,15 @@ jest.mock("next/headers", () => ({
|
|||||||
|
|
||||||
// Error and Loading Pages
|
// Error and Loading Pages
|
||||||
describe("Error and Loading Pages", () => {
|
describe("Error and Loading Pages", () => {
|
||||||
// it("Error Page should render without crashing", async () => {
|
it("Error Page should render without crashing", () => {
|
||||||
// render(await Error());
|
render(<Error error={mockError} reset={mockReset} />);
|
||||||
// });
|
|
||||||
|
|
||||||
it("Loading Page should render without crashing", async () => {
|
|
||||||
render(await Loading());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Not Found Page should render without crashing", async () => {
|
it("Loading Page should render without crashing", () => {
|
||||||
render(await NotFound());
|
render(Loading());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Not Found Page should render without crashing", () => {
|
||||||
|
render(NotFound());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
4
__tests__/page/utils.ts
Normal file
4
__tests__/page/utils.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// #TODO move mock functions here
|
||||||
|
// Circumvent naming conflict, don't delete/move form this file
|
||||||
|
export const mockError = new Error();
|
||||||
|
export const mockReset = () => {};
|
||||||
@ -2,26 +2,13 @@ import { render } from "@testing-library/react";
|
|||||||
|
|
||||||
// Pages - Verification
|
// Pages - Verification
|
||||||
import VerifyPage from "@/app/verify/page";
|
import VerifyPage from "@/app/verify/page";
|
||||||
|
import React from "react";
|
||||||
// Mock Cookies
|
|
||||||
jest.mock("next/headers", () => ({
|
|
||||||
cookies: jest.fn(() => ({
|
|
||||||
getAll: jest.fn(() => [{ name: "test", value: "cookieValue" }]), // Simulate returning cookies
|
|
||||||
setAll: jest.fn(), // Simulate setAll method
|
|
||||||
})),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Mock Router
|
// Mock Router
|
||||||
jest.mock('next/navigation', () => ({
|
jest.mock('next/navigation', () => ({
|
||||||
useRouter: jest.fn().mockReturnValue({
|
useRouter: jest.fn().mockReturnValue({
|
||||||
push: jest.fn(),
|
push: jest.fn(),
|
||||||
replace: jest.fn(),
|
|
||||||
prefetch: jest.fn(),
|
|
||||||
pathname: '/',
|
|
||||||
query: {},
|
|
||||||
asPath: '/',
|
|
||||||
}),
|
}),
|
||||||
usePathname: jest.fn(() => '/'),
|
|
||||||
useSearchParams: jest.fn(() => ({
|
useSearchParams: jest.fn(() => ({
|
||||||
get: jest.fn((key) => {
|
get: jest.fn((key) => {
|
||||||
if (key === 'email') return 'test@example.com'; // Mock behavior for 'email' query param
|
if (key === 'email') return 'test@example.com'; // Mock behavior for 'email' query param
|
||||||
@ -31,8 +18,9 @@ jest.mock('next/navigation', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Verification Pages
|
// Verification Pages
|
||||||
// describe("Verification Pages", () => {
|
describe("Verification Pages", () => {
|
||||||
// it("Verify Page should render without crashing", () => {
|
it("Verify Page should render without crashing", () => {
|
||||||
// render(VerifyPage());
|
jest.spyOn(React, 'useEffect').mockImplementation((f) => f());
|
||||||
// });
|
render(VerifyPage());
|
||||||
// });
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user