Skip to content

Commit a74e1c6

Browse files
committed
add tests for useForceUpdate
1 parent 030ce69 commit a74e1c6

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference types="vitest-dom/extend-expect" />
2+
3+
import * as React from "react";
4+
import { render, cleanup, userEvent } from "@reach-internal/test/utils";
5+
import { afterEach, describe, expect, it } from "vitest";
6+
import { useForceUpdate } from "@reach/utils";
7+
8+
afterEach(cleanup);
9+
10+
describe("useForceUpdate", () => {
11+
it("TODO", async () => {
12+
let nonObservableVariable = "foo";
13+
14+
const Test = () => {
15+
const forceUpdate = useForceUpdate();
16+
return (
17+
<>
18+
<div data-testid="div">{nonObservableVariable}</div>
19+
<button data-testid="button" onClick={forceUpdate} />
20+
</>
21+
);
22+
};
23+
24+
const { getByTestId } = render(<Test />);
25+
const div = getByTestId("div");
26+
const button = getByTestId("button");
27+
28+
expect(div).toHaveTextContent("foo");
29+
nonObservableVariable = "bar";
30+
expect(div).toHaveTextContent("foo");
31+
await userEvent.click(button);
32+
expect(div).toHaveTextContent("bar");
33+
});
34+
});

0 commit comments

Comments
 (0)