【发布时间】:2022-12-07 12:02:43
【问题描述】:
要求:检查 DOM 上是否存在图标。
我写的测试用例:
render(
<div>
<svg height="100" width="100">
<circle cx="10" cy="10" r="10" stroke="black" fill="red" />
</svg>
</div>
);
expect(screen.getByRole('graphics-document')).toBeInTheDocument();
[角色列表已在 W3 documentation 中定义,由 Jest documentation 引用。]
错误:
上面的测试用例给出了以下错误:
TestingLibraryElementError: Unable to find an accessible element with the role "graphics-document"
SVG 图标正在 DOM 上呈现,但测试用例失败。为什么以及如何解决这个问题?
【问题讨论】:
标签: reactjs unit-testing testing jestjs react-testing-library