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!