Skip to content

Commit

Permalink
Rename old test case, add test for navigation with query string
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityTwoG committed Jul 4, 2024
1 parent 609cc5e commit a1aaf39
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/wouter/test/use-hash-location.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ it("should not rerender when pathname changes", () => {
expect(result.current).toBe(1);
});

it("does not change anything besides the hash", () => {
it("does not change anything besides the hash when doesn't contain ? symbol", () => {
history.replaceState(null, "", "/foo?bar#/app");

const { result } = renderHook(() => useHashLocation());
Expand All @@ -75,6 +75,18 @@ it("does not change anything besides the hash", () => {
expect(location.search).toBe("?bar");
});

it("changes search and hash when contains ? symbol", () => {
history.replaceState(null, "", "/foo?bar#/app");

const { result } = renderHook(() => useHashLocation());
const [, navigate] = result.current;

navigate("/abc?def");
expect(location.pathname).toBe("/foo");
expect(location.search).toBe("?def");
expect(location.hash).toBe("#/abc");
});

it("creates a new history entry when navigating", () => {
const { result } = renderHook(() => useHashLocation());
const [, navigate] = result.current;
Expand Down

0 comments on commit a1aaf39

Please sign in to comment.