import { describe, it, expect, vi, beforeEach } from "vitest"; import { navigateBack } from "./navigation"; const goto = vi.fn(); vi.mock("$app/navigation", () => ({ goto: (...args: unknown[]) => goto(...args), })); describe("navigateBack", () => { beforeEach(() => { goto.mockClear(); }); it("pops real history when there is in-app history to go back to", () => { const back = vi.fn(); vi.spyOn(history, "back").mockImplementation(back); vi.spyOn(history, "length", "get").mockReturnValue(3); navigateBack("/library"); expect(back).toHaveBeenCalledOnce(); expect(goto).not.toHaveBeenCalled(); }); it("falls back to the given path on a fresh deep-link (no history)", () => { const back = vi.fn(); vi.spyOn(history, "back").mockImplementation(back); vi.spyOn(history, "length", "get").mockReturnValue(1); navigateBack("/library/music"); expect(goto).toHaveBeenCalledWith("/library/music"); expect(back).not.toHaveBeenCalled(); }); });