For my use case, using the dropzone defined in @Lin Du's answer I needed to do some additional work.
import { createEvent, fireEvent, render, screen, waitFor } from '@testing-library/react';
describe('Dropzone tests', () => {
test('handles multiple file drops', async () => {
render(<App />);
const mockFiles = [
new File(['file1'], 'image1.png', { type: 'image/png' }),
new File(['file2'], 'image2.png', { type: 'image/png' }),
new File(['file3'], 'image3.jpg', { type: 'image/jpeg' }),
new File(['file4'], 'image4.jpg', { type: 'image/jpeg' }),
new File(['file5'], 'image5.gif', { type: 'image/gif' }),
new File(['file6'], 'image6.jpg', { type: 'image/jpeg' }),
];
const dropzone = screen.getByTestId('dropzone');
const dropEvent = createEvent.drop(dropzone);
Object.defineProperty(dropEvent, 'dataTransfer', {
value: {
files: mockFiles,
items: mockFiles.map(file => ({
kind: 'file',
type: file.type,
getAsFile: () => file,
})),
types: ['Files'],
},
});
fireEvent(dropzone, dropEvent);
await waitFor(() => {
mockFiles.forEach(file => {
expect(screen.getByText(file.name)).toBeInTheDocument();
});
});
});
});