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'});

可以在这里找到一个带有几个测试的小示例片段:

反应测试库演示

4

1 回答 1

0

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

于 2018-08-20T17:05:14.280 回答