1

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:

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!

Fan Li
  • 1,057
  • 7
  • 11

0 Answers0