我想测试工具提示标题是否等于特定文本。 这是我的antd工具提示,我想为它编写一个测试:
<Tooltip
title={
this.props.connection ? "Connected" : "Disconnected (Try again)"
}>
<Badge status="default" data-testid="connection-sign" />
</Tooltip>
这是我在 Jest 中的测试:
test("Show error title in tooltip", async () => {
baseDom = render(cardComponent);
fireEvent.mouseMove(await baseDom.findByTestId("connection-sign")); //To hover element and show tooltip
expect(
baseDom.getByTitle(
"Disconnected (Try again)"
)
).toBeInTheDocument();
});
但是这个测试失败了,无法找到具有该标题的元素。我该如何测试我的工具提示是否包含“已断开连接(请重试)”?
Tooltip
组件来自哪里?是自定义的还是来自 material-ui 或其他地方? - Rostyslav