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

Using a real DataTransfer object with a drop event fails

Open Beginner friendly
#857 0 comments 0 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: latest
  • Testing Framework and version:
  • DOM Environment:
Relevant code or config:

https://github.com/testing-library/dom-testing-library/blob/accb6cc60628cb6b5bd4d9be2ead41724995e5ae/src/events.js#L74 - this assumes it only needs to copy across named properties - But if the caller uses an actual DataTransfer object e.g. by calling new window.DataTransfer() - adding data to it and passing it in, then this won't read the properties off it.

Try it for yourself - in Chrome Object.getOwnPropertyNames(new window.DataTransfer()) returns an empty array.

This means - it's impossible to use a DataTransfer object, add data to it and then use it for the event.

Suggested solution:

if the dataTransfer value passed to the event is an actual instance of window.DataTransfer then just pass it on - don't try to copy properties over to a new instance

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 in src/events.js at the referenced line, where event properties are copied into a new event value. Reproduce the drop-event case with a real DataTransfer object, then verify that its data remains available when the event is dispatched.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.