-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fireEvent.drop is not including event.dataTransfer #339
Comments
Hi @christopher-schroer, I'm not sure what this could be. Without a simple reproduction in a codesandbox there's only so much we can do. |
@kentcdodds I figured as much. Once I have some free time, I will try to create a repo for sharing. Unfortunately, I'm going to be on vacation until Apr 11. |
I managed to put together a basic example https://github.com/christopher-schroer/react-testing-library-drop-issue Clone it, run |
Ah, this appears to be an issue with jsdom not supporting You could file an issue against jsdom to see what it would take to contribute support for dataTransfer. |
Closing this in favor of: jsdom/jsdom#1568 Thanks. |
For anyone that finds their way to this ticket via a search whilst they are stuck on the same problem, I managed to work around the limitation in jsdom using
I'm not sure how evil this approach is, but it might come in handy :) |
Seems legit. Would be cool to get this added to the examples: https://codesandbox.io/s/github/kentcdodds/react-testing-library-examples |
@andypearson I wasn't able to get that exact code to work, but I got a very similar version working: const fileDropzone = getByText('Drag and Drop Excel Files Here');
const fileDropEvent = createEvent.drop(fileDropzone);
const fileList = [file];
Object.defineProperty(fileDropEvent, 'dataTransfer', {
value: {
files: {
item: itemIndex => fileList[itemIndex],
length: fileList.length,
},
},
});
fireEvent(fileDropzone, fileDropEvent); Key differences here: I'm using the RTL Rather than return |
@kentcdodds I'll see what I can do! |
For anyone testing drag and drop and wants to test Second approach with using A quick workaround for me was to use Full working example as of `test('on drag start sets dataTransfer property correctly', () => {
|
react-testing-library
version: 6.0.1react
version: 16.8.1node
version: 8.9.4npm
version: 5.6.0jest
version: 24.0.0Relevant code or config:
Below is a simplified, generic version of my code
What you did:
I am trying to test a drop event that is used for uploading files via drag-and-drop
What happened:
When I run my unit test, the event is firing, but I get the following error
TypeError: Cannot read property 'files' of undefined
When I do a
console.log
of the event it shows thatevent.dataTransfer
is undefined.Reproduction:
Unable to provide a link to code repository due to the repo being private
Problem description:
Unable to test file upload via drag-and-drop using
react-testing-library
The text was updated successfully, but these errors were encountered: