Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use fireEvent.drop with dataTransfer #1350

Open
DEfusion opened this issue Feb 12, 2025 · 0 comments
Open

Can't use fireEvent.drop with dataTransfer #1350

DEfusion opened this issue Feb 12, 2025 · 0 comments

Comments

@DEfusion
Copy link

  • @testing-library/dom version: 10.4.0
  • Testing Framework and version: @storybook/test@npm:8.4.7
  • DOM Environment:
    • Chrome: Error "Failed to construct 'DragEvent': Failed to read the 'dataTransfer' property from 'DragEventInit': Failed to convert value to 'DataTransfer'."
    • Firefox: Error "DragEvent constructor: 'dataTransfer' member of DragEventInit does not implement interface DataTransfer."
    • Safari: Error "TypeError: Type error"

Following the docs for fireEvent, I tried the following:

const dropzone = getByLabelText('File dropzone');
fireEvent.drop(dropzone), {
  dataTransfer: {
    files: [new File(['(⌐□_□)'], 'chucknorris.png', {type: 'image/png'})],
  },
})

Which gives me this error:

Failed to construct 'DragEvent': Failed to read the 'dataTransfer' property from 'DragEventInit': Failed to convert value to 'DataTransfer'.

If I create the event manually like so then this works:

const event = new Event('dragover');
event.dataTransfer = {
  files: [new File(['(⌐□_□)'], 'chucknorris.png', { type: 'image/png' })],
};
await fireEvent(dropzone, event);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant