Skip to content

💡Add dataTransfer to fireEvent eventProperties #551

Closed
@jamsinclair

Description

@jamsinclair

Describe the feature you'd like:

Optionally populate dataTransfer property and its files for Drop events. Similar to existing target feature

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

Describe alternatives you've considered:

// if jsdom ever supports DragEvent or DataTransfer we'd need to use defineProperty 
// to override the readonly property
const dropEvent = new Event('drop');
Object.assign(dropEvent, {
  dataTransfer: {
    files: [new File(['(⌐□_□)'], 'chucknorris.png', { type: 'image/png' })]
  }
});
fireEvent(getByLabelText('Drop files here'), dropEvent)

This is probably a very niche feature request. 99% of users won't be testing drag 'n' drop forms. Please close this issue if the alternative is adequate.

Teachability, Documentation, Adoption, Migration Strategy:

Add dataTransfer section to existing page at https://testing-library.com/docs/dom-testing-library/api-events

Edit

I see this was discussed in the react repo, testing-library/react-testing-library#339.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions