Open cossack910 opened 1 year ago
解決
describe("Input form onChnage event", () => {
it("入力値テスト", async () => {
render(<RenderInput outputConsole={console.log} />);
const inputValue = screen.getByPlaceholderText("enter") as HTMLInputElement; //型キャストしないとvalueで警告
await userEvent.type(inputValue, "test");
expect(inputValue.value).toBe("test");
});
});
userEvent.type が入力をシミュレートする速度が速すぎて、Reactの更新が間に合っていなかった。
awaitを入れて入力値がtestになるまで待ってからマッチャする。
問題コード