Reactjs 无法在具有特定名称的listitem上使用getByRole-RTL
如果这是一个重复的问题,我很抱歉。我在其他任何地方都找不到答案 组成部分:Reactjs 无法在具有特定名称的listitem上使用getByRole-RTL,reactjs,testing,jestjs,react-testing-library,testing-library,Reactjs,Testing,Jestjs,React Testing Library,Testing Library,如果这是一个重复的问题,我很抱歉。我在其他任何地方都找不到答案 组成部分: <ul> <li>Pending tasks</li> </ul> 错误: TestingLibraryElementError: Unable to find an accessible element with the role "listitem" and name "Pending tasks" 下面是codesand
<ul>
<li>Pending tasks</li>
</ul>
错误:
TestingLibraryElementError: Unable to find an accessible element with the role "listitem" and name "Pending tasks"
下面是codesandbox链接,用于复制此内容:
即使它显示错误,表示找不到,它仍然建议将me li和ul标记作为可用角色
Here are the accessible roles:
--------------------------------------------------
list:
Name "":
<ul />
--------------------------------------------------
listitem:
Name "":
<li />
以下是可访问的角色:
--------------------------------------------------
名单:
名称“”:
--------------------------------------------------
列表项:
名称“”:
有人能解释一下我遗漏了什么吗?
我尝试使用正则表达式匹配器,但没有成功。一个
列表项
由作者按spec()命名
作者的姓名定义为
author:name来自作者在显式标记功能(如aria label属性、aria labelledby属性)或宿主语言标记机制(如HTML中的alt或title属性)中提供的值,其中HTML title属性在指定文本替代项时具有最低优先级
--
这并不意味着你应该给它一个咏叹调标签。只有在确定辅助技术存在问题时,才应添加aria属性
对于您的特定查询,我建议使用getAllByRole('listitem').filter(listitem=>listitem.textContent=='Pending task')
Here are the accessible roles:
--------------------------------------------------
list:
Name "":
<ul />
--------------------------------------------------
listitem:
Name "":
<li />