diff --git a/packages/wouter/test/memory-location.test.ts b/packages/wouter/test/memory-location.test.ts index 5b20a99..7ae3c00 100644 --- a/packages/wouter/test/memory-location.test.ts +++ b/packages/wouter/test/memory-location.test.ts @@ -23,6 +23,17 @@ it("should support initial path", () => { unmount(); }); +it("should support initial path with query", () => { + const { searchHook } = memoryLocation({ path: "/test-case?foo=bar" }); + // const { searchHook } = memoryLocation({ path: "/test-case", searchPath: "foo=bar" }); + + const { result, unmount } = renderHook(() => searchHook()); + const [value] = result.current; + + expect(value).toBe("foo=bar"); + unmount(); +}); + it('should return location hook that has initial path "/" by default', () => { const { hook } = memoryLocation(); @@ -33,6 +44,16 @@ it('should return location hook that has initial path "/" by default', () => { unmount(); }); +it('should return search hook that has initial query "" by default', () => { + const { searchHook } = memoryLocation(); + + const { result, unmount } = renderHook(() => searchHook()); + const [value] = result.current; + + expect(value).toBe(""); + unmount(); +}); + it("should return standalone `navigate` method", () => { const { hook, navigate } = memoryLocation(); diff --git a/packages/wouter/test/use-search.test.tsx b/packages/wouter/test/use-search.test.tsx index ad8fe4d..43e7823 100644 --- a/packages/wouter/test/use-search.test.tsx +++ b/packages/wouter/test/use-search.test.tsx @@ -1,6 +1,7 @@ import { renderHook, act } from "@testing-library/react"; import { useSearch, Router } from "wouter"; import { navigate } from "wouter/use-browser-location"; +import { memoryLocation } from "wouter/memory-location"; import { it, expect, beforeEach } from "vitest"; beforeEach(() => history.replaceState(null, "", "/")); @@ -24,6 +25,18 @@ it("can be customized in the Router", () => { expect(result.current).toEqual("none"); }); +it("can be customized with memoryLocation", () => { + const { searchHook } = memoryLocation({ path: "/foo?key=value" }); + + const { result } = renderHook(() => useSearch(), { + wrapper: (props) => { + return {props.children}; + }, + }); + + expect(result.current).toEqual("key=value"); +}); + it("unescapes search string", () => { const { result: searchResult } = renderHook(() => useSearch());