React 测试库:无法测试隐藏按钮
我的应用程序中有一个编辑按钮。单击编辑按钮后,编辑按钮消失,并在该位置呈现两个新按钮。 (保存并取消)。
我必须测试保存和取消功能。 尝试过: const save = wait screen.findByTestId('save') 单击事件被触发后。
运行此错误时,未找到带有保存测试 ID 的元素。
I have an edit button in my application. After clicking the edit button, the Edit button got disappeared and two new buttons were rendered on that place. (Save and Cancel).
I've to test the save and cancel functionality.
Tried:
const save = await screen.findByTestId('save')
After click event is fired.
On Running this getting error that no element is found with save test id.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用以下代码等待按钮出现:
await waitFor(() => screen.findByRole('button', {name:/save/i, hide: true })
您可以也可以尝试 -
await waitFor(() => screen.findAllByRole('button', {name:/save/i, hide: true })
在此处查看更多信息 - React 测试库链接
Try the below code to wait for the button to appear:
await waitFor(() => screen.findByRole('button', {name:/save/i, hidden: true })
You can also try -
await waitFor(() => screen.findAllByRole('button', {name:/save/i, hidden: true })
Check here for more info - React Testing Lib Link