如果这是一个重复的问题,我深表歉意。我在其他任何地方都找不到答案。
零件:
<ul>
<li>Pending tasks</li>
</ul>
测试代码:
expect(getByRole("listitem", { name: "Pending tasks" })).toBeInTheDocument();
错误:
TestingLibraryElementError: Unable to find an accessible element with the role "listitem" and name "Pending tasks"
这是重现此内容的代码框链接: https ://codesandbox.io/s/wandering-browser-mrf78?file=/src/App.test.js
即使它显示错误提示无法找到,它仍然建议我将 li & ul 标签作为可用角色。
Here are the accessible roles:
--------------------------------------------------
list:
Name "":
<ul />
--------------------------------------------------
listitem:
Name "":
<li />
有人可以解释一下我在这里缺少什么吗?我尝试使用正则表达式匹配器,但没有运气。