テキストボックスへの入力テスト
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import React from "react"; import { render, screen, cleanup } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import Input from "./Input"; describe("入力", () => { it("入力テスト", () => { render(<Input />); const inputValue = screen. getByRole("textbox"); userEvent.type(inputValue, "test"); expect(inputValue.value).toBe("test"); }); }); |
userEvent.type(inputValue, “test”);
第一引数で指定したテキストボックスに対して第二引数の「test」という文字列を入力していることをシミュレートすることができます。
expect(inputValue.value).toBe(“test”);
toBeというマッチャを使えば値の一致をチェックすることができます。
この記事へのコメントはありません。