testing-library / testing-library/user-event

Export createDataTransfer util function

Open
#1,245 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
2.3k
Forks
258
PR merge metrics
No merged PRs in 30d

Description

Problem description

When testing paste functionality, it would be really helpful to be able to use the internal createDataTransfer functionality.

I've previously created a simple mock of the DataTransfer object but this can cause frustrating test failures when it doesn't behave in exactly the same way that user-event expects it to, e.g. returning the text/plain data when getData('text') is called.

Suggested solution

Since user-event's paste functionality seems to expect that the mocked DataTransfer object behaves as the internally mocked version does, it would be really helpful to expose createDataTransfer to allow the user to create an instance of that version.

Additional context

No response

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 by locating the internal createDataTransfer function and the package's public export entry point, then inspect the existing paste-related tests. The work is complete when consumers can import createDataTransfer and use it to create the same DataTransfer mock expected by paste functionality, with the relevant tests passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.