GetByRole 在反应测试库中返回一些元素

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

给定匹配多个元素的 getByRole 选择器。它会返回什么? https://testing-library.com/docs/queries/byrole/

getByRole('button')

<body>

  <main>

    <button>Open dialog</button>

  </main>

  <div role="dialog">

    <button>Close dialog</button>

  </div>

</body>

会返回什么? 元素很少,有匹配的元素还是抛出错误?

https://testing-library.com/docs/queries/byrole/

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

根据文档, getBy 方法“返回查询的匹配节点,如果没有元素匹配或如果找到多个匹配项,则抛出描述性错误

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