Skip to content

Commit

Permalink
fix test with fake timers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeetiss authored and molefrog committed Jun 11, 2023
1 parent 530eaa4 commit db9a87a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/wouter/test/use-location.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from "react";
import { it, expect, describe, beforeEach } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { renderHook, act, waitFor } from "@testing-library/react";
import useLocation, { navigate, useSearch } from "wouter/use-location";

it("returns a pair [value, update]", () => {
Expand Down Expand Up @@ -32,20 +32,17 @@ describe("`value` first argument", () => {
unmount();
});

// Vitest doesn't support Jest's legacy timers.
it.skip("supports history.back() navigation", () => {
// jest.useFakeTimers();
it("supports history.back() navigation", async () => {
const { result, unmount } = renderHook(() => useLocation());

act(() => history.pushState(null, "", "/foo"));
expect(result.current[0]).toBe("/foo");
await waitFor(() => expect(result.current[0]).toBe("/foo"));

act(() => {
history.back();
// jest.runAllTimers();
});

expect(result.current[0]).toBe("/");
await waitFor(() => expect(result.current[0]).toBe("/"));
unmount();
});

Expand Down

0 comments on commit db9a87a

Please sign in to comment.