UNPKG

generate-routes-refs

Version:

A package to generate route references for React Router 7

40 lines 1.9 kB
import { describe, expect, it } from "vitest"; import { getRouteId } from "./get-route-id.js"; describe("getRouteId", () => { it("should return the route path when removeFromRouteKey is not provided", () => { const route = { id: "test", path: "/users/profile" }; const options = {}; expect(getRouteId(route, options)).toBe("/users/profile"); }); it("should remove the specified part from the route path", () => { const route = { id: "test", path: "/users/profile" }; const options = { removeFromRouteKey: "/users" }; expect(getRouteId(route, options)).toBe("/profile"); }); it("should return the full route path if removeFromRouteKey does not match", () => { const route = { id: "test", path: "/users/profile" }; const options = { removeFromRouteKey: "/admin" }; expect(getRouteId(route, options)).toBe("/users/profile"); }); it("should return an empty string if route path is undefined", () => { const route = { id: "test", path: undefined }; const options = {}; expect(getRouteId(route, options)).toBe(""); }); it("should return an empty string if route path is an empty string", () => { const route = { id: "test", path: "" }; const options = {}; expect(getRouteId(route, options)).toBe(""); }); it("should handle complex removals", () => { const route = { id: "test", path: "a/b/c/d/e" }; const options = { removeFromRouteKey: "a/b/c" }; expect(getRouteId(route, options)).toBe("/d/e"); }); it("should return an empty string if the whole path is removed", () => { const route = { id: "test", path: "/users/profile" }; const options = { removeFromRouteKey: "/users/profile" }; expect(getRouteId(route, options)).toBe(""); }); }); //# sourceMappingURL=get-route-id.test.js.map