import { NextResponse, NextRequest } from "next/server"; import { GET } from "@/app/api/hobbies/route"; // Mock the route handler module jest.mock("@/app/api/hobbies/route", () => ({ GET: jest.fn(), })); describe("GET /api/hobbies", () => { it("should return hobbies", async () => { (GET as jest.Mock).mockResolvedValue( NextResponse.json({ hobbies: [{ id: 1, title: "Gaming" }] }) ); const response = await GET({} as NextRequest); const data = await response.json(); expect(response.status).toBe(200); expect(data.hobbies).toHaveLength(1); }); });