* refactor: apply biome formatting to small packages + packages/lib Format packages/sms, packages/prisma, packages/platform/libraries, packages/platform/examples, packages/platform/types, packages/emails, and packages/lib. Excludes packages/platform/examples/base/src/pages/[bookingUid].tsx due to pre-existing lint errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert: remove packages/platform formatting changes Revert biome formatting for packages/platform as requested. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
import { renderHook } from "@testing-library/react-hooks";
|
|
import { vi } from "vitest";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { useCompatSearchParams } from "./useCompatSearchParams";
|
|
|
|
vi.mock("next/navigation", () => ({
|
|
ReadonlyURLSearchParams: vi.fn().mockImplementation(function (a) {
|
|
return a;
|
|
}),
|
|
}));
|
|
|
|
describe("useCompatSearchParams hook", () => {
|
|
it("should return the searchParams in next@13.4.6 Pages Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a&b=b"));
|
|
navigation.useParams = vi.fn().mockReturnValue(null);
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=a&b=b");
|
|
});
|
|
|
|
it("should return both searchParams and params in next@13.4.6 App Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a"));
|
|
navigation.useParams = vi.fn().mockReturnValue({ b: "b" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=a&b=b");
|
|
});
|
|
|
|
it("params should always override searchParams in case of conflicting keys", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a"));
|
|
navigation.useParams = vi.fn().mockReturnValue({ a: "b" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=b");
|
|
});
|
|
|
|
it("should split paramsseparated with '/' (catch-all segments) in next@13.4.6 App Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams());
|
|
// in next@13.4.6 useParams will return params separated by `/`
|
|
navigation.useParams = vi.fn().mockReturnValue({ a: "a/b/c" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.getAll("a")).toEqual(["a", "b", "c"]);
|
|
});
|
|
|
|
it("should include params and searchParams in next@13.5.4, Pages/App Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a"));
|
|
navigation.useParams = vi.fn().mockReturnValue({ b: "b" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=a&b=b");
|
|
});
|
|
});
|