Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536import { describe, expect, it, vi } from "vitest";import { navigatingTo } from "$lib/navPulse";
const mockNavigating = vi.hoisted(() => ({ to: null as { url: URL } | null}));
vi.mock("$app/state", () => ({ navigating: mockNavigating}));
describe("navigatingTo", () => { it("returns false when there is no active navigation", () => { mockNavigating.to = null; expect(navigatingTo("/alice/repo")).toBe(false); });
it("returns true when navigating to the matching href path", () => { mockNavigating.to = { url: new URL("https://tangled.org/alice/repo") }; expect(navigatingTo("/alice/repo")).toBe(true); expect(navigatingTo("https://tangled.org/alice/repo")).toBe(true); });
it("returns false when navigating to a different path", () => { mockNavigating.to = { url: new URL("https://tangled.org/alice/repo/tree/main") }; expect(navigatingTo("/alice/repo")).toBe(false); expect(navigatingTo("/alice/other-repo")).toBe(false); });
it("matches pathnames regardless of search params or hashes in href or to", () => { mockNavigating.to = { url: new URL("https://tangled.org/alice/repo?tab=overview#section") }; expect(navigatingTo("/alice/repo")).toBe(true); expect(navigatingTo("/alice/repo?tab=repos")).toBe(true); });});