testing-library / testing-library/dom-testing-library

Can't use `fireEvent.drop` with `dataTransfer`

Open
#1,350 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

  • @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);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the fireEvent entry point and reproduce the reported fireEvent.drop example with dataTransfer in Chrome, Firefox, and Safari. Done means the documented dataTransfer payload works without the reported DragEvent conversion errors, with coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.