使用故事书交互测试的真实剪贴板事件?
我对如何使用 Jest 和 React-Testing-Library 测试真实的 onPaste
剪贴板事件做了一些研究,并意识到这是一个挑战:
Storybook 交互式测试在真实的浏览器中运行,我希望它应该是可能的。
https://storybook.js.org/blog/interaction-testing-with -storybook/
但是我的测试不成功。
await userEvent.paste(inputEl, 'some text')
无法从我的 handlePaste
函数访问剪贴板数据:
const handlePaste = (event: ClipboardEvent<HTMLInputElement>) => {
event.preventDefault()
const pasted = event.clipboardData.getData('text/plain')
...
}
TypeError
Cannot read properties of null (reading 'getData')
谢谢!
I did some research on how to test real onPaste
Clipboard event with Jest and React-Testing-Library and realized that it is a challenge:
- How to paste clipboard data using React Testing Library?
- How to mock onPast event with React and Jest?
- How to fire and test a real paste event (not simulated by calling the prop) in Jest and Enzyme
Now that Storybook Interactive Testing runs in a real browser, I am hoping it should be possible.
https://storybook.js.org/blog/interaction-testing-with-storybook/
But my test was unsuccessful.
await userEvent.paste(inputEl, 'some text')
Not able to access clipboard data from my handlePaste
function:
const handlePaste = (event: ClipboardEvent<HTMLInputElement>) => {
event.preventDefault()
const pasted = event.clipboardData.getData('text/plain')
...
}
TypeError
Cannot read properties of null (reading 'getData')
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论