0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【React】Testing Libraryのロール名のメモ

Posted at

Testing Libraryでロール名が分からないときがあったので書き留めておく

h1~h6タグ

const xxx = screen.getByRole('heading');
expect(xxx).toBeInTheDocument();

buttonタグ

const xxx = screen.getByRole('button');
expect(xxx).toBeInTheDocument();

inputタグ テキストボックス

const xxx = screen.getByRole('textbox');
expect(xxx).toBeInTheDocument();

inputタグ ラジオボタン

const xxx = screen.getByRole('radio');
expect(xxx).toBeInTheDocument();

inputタグ チェックボックス

const xxx = screen.getByRole('checkbox');
expect(xxx).toBeInTheDocument();

liタグ

const xxx = screen.getAllByRole('listitem');
expect(xxx).toBeInTheDocument();

liは基本的には複数存在するので、getAllByRoleとします。

主に使いそうなのはここら辺でした。
参考はこちら

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?