Skip to content

Commit

Permalink
test: refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
jijiseong committed Jul 18, 2024
1 parent cd9d9db commit 68050a8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/components/input/__tests__/input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import {render, renderHook, fireEvent} from "@testing-library/react";
import {render, renderHook, fireEvent, act} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import {useForm} from "react-hook-form";

Expand Down Expand Up @@ -182,20 +182,26 @@ describe("Input", () => {
});

it("should sync ref.current.value with input's value after clicking the input", async () => {
const user = userEvent.setup();
const ref = React.createRef<HTMLInputElement>();

const {container} = render(<Input ref={ref} value="value" />);
const inputBase = container.querySelector("[data-slot='base']");
const input = inputBase?.querySelector("input");

const user = userEvent.setup();
expect(ref.current).not.toBeNull();

const inputBase = container.querySelector("[data-slot='base']");

expect(inputBase).not.toBeNull();

const input = container.querySelector("input");

expect(input).not.toBeNull();
expect(ref.current).not.toBeNull();

ref.current!.value = "new value";
await user.click(inputBase!);

await act(async () => {
await user.click(inputBase!);
});
expect(input).toHaveValue("new value");
});
});
Expand Down

0 comments on commit 68050a8

Please sign in to comment.