jeudi 15 octobre 2020

How to get or query the specified HTML element by @test-library/react?

<input type="radio" class="ThemeType-1" name="themeSwitch" value="Dark" checked>
<input type="radio" class="ThemeType-2" name="themeSwitch" value="Light" >

if I use screen.getByText("Dark"), it can't find the element/control.

and I want to get it by ClassName, but it seems test-library doesn't provide that method. (most methods are get/query/ byText)

the querySelector can only set one parameter such as div, input, etc. I want to query the input with Class named "ThemeType-1" or name "themeSwitch". I don't know how to do that.

So, how can I use test-library/react to query or get the above element and then check its property such as value, checked, etc?

Thanks a lot.

Aucun commentaire:

Enregistrer un commentaire