Closed
Description
react-testing-library
version: 6.0.1react
version: 16.8.1node
version: 8.9.4npm
version: 5.6.0jest
version: 24.0.0
Relevant code or config:
Below is a simplified, generic version of my code
export const FileDropZone = props => {
const handleDrop = useCallback(
event => {
event.stopPropagation();
event.preventDefault();
handleFiles(event.dataTransfer.files);
},
[handleFiles]
);
// Rest of code
return (
<div
onDragEnter={handleDragEnter}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
>
Drag File Here
</div>
);
}
describe('FileDropZone', () => {
test('should handle a file being dropped in the drop zone', () => {
const file = new File(['(⌐□_□)'], 'chucknorris.png', {
type: 'image/png',
})
const {getByText, queryByText} = render(<FileDropZone {...props} />);
expect(queryByText('chucknorris.png')).toBeNull();
const dropZone = getByText('Drag File Here');
act(() => {
fireEvent.drop(dropZone, {dataTransfer: {files: [file]}});
});
expect(queryByText('chucknorris.png')).toBeInTheDocument();
})
})
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 that event.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