Skip to content

Commit

Permalink
add tests for useForceUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
dartess committed Aug 25, 2022
1 parent 030ce69 commit 7111180
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/utils/__tests__/use-force-update.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// <reference types="vitest-dom/extend-expect" />

import * as React from "react";
import { render, cleanup, userEvent } from "@reach-internal/test/utils";
import { afterEach, describe, expect, it } from "vitest";
import { useForceUpdate } from "@reach/utils";

afterEach(cleanup);

describe("useForceUpdate", () => {
it("should force rerender when called", async () => {
let nonObservableVariable = "foo";

const Test = () => {
const forceUpdate = useForceUpdate();
return (
<>
<div data-testid="div">{nonObservableVariable}</div>
<button data-testid="button" onClick={forceUpdate} />
</>
);
};

const { getByTestId } = render(<Test />);
const div = getByTestId("div");
const button = getByTestId("button");

expect(div).toHaveTextContent("foo");
nonObservableVariable = "bar";
expect(div).toHaveTextContent("foo");
await userEvent.click(button);
expect(div).toHaveTextContent("bar");
});
});

0 comments on commit 7111180

Please sign in to comment.