Skip to content
Advertisement

How to test properly React Dropzone onDrop method

I’m testing React Dropzone and I need to check the onDrop function. This function has two parameters (acceptedFiles and rejectedFiles). I’m mocking the files like this:

JavaScript

Then in my test, I do that:

JavaScript

This is my onDrop function:

JavaScript

The expected result would be that handleOnDrop returns acceptedFiles but returns rejectedFiles and I don’t know why.

Mime type it’s ok and also size.

That’s the function from react-dropzone:

JavaScript

Thanks.

Advertisement

Answer

When passing

JavaScript

Into

JavaScript

It will think image is undefined or null. The way I was able to fix this is

JavaScript

This of course is how you would do it for a plain text file. For different types of images you will want to specify the image type instead of doing “text/plain”

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement