无法使用dom-testing-library访问其父级标签的输入

问题描述 投票:1回答:1

当标签环绕输入时,我发现自己无法尝试从标签访问输入。这看起来像是一个容易解决的问题,但我有一点时间。

<label htmlFor="termsAgreement">
    <input type="checkbox" name="termsAgreement"/>
    <p>Here are the terms of use</p>
</label>

我以为以下可行,但没有运气:

getByLabelText('Here are the terms of use', {selector: 'input'});

可以在此处找到带有几个测试的小示例代码段:

react-testing-library demo

reactjs jestjs react-testing-library
1个回答
0
投票

看起来我正在使用name字段而不是预期的id字段来定位相关的输入。

© www.soinside.com 2019 - 2024. All rights reserved.