I am using Ant Design's Upload component.
<Upload
accept=".xlsx"
onChange={onImport}
>
<Button>Upload</Button>
</Upload>
I have attempted to simulate the change using fireEvent.change which does nothing:
const inputEl = screen.getByText('Import');
const file = new File(['(⌐□_□)'], 'chucknorris.xlsx');
fireEvent.change(inputEl, { target: { files: [file] } });
I also tried to use fireEvent.drop. I tried setting both the dataTransfer and files properties.
Object.defineProperty(inputEl, 'dataTransfer', {
value: {
files: [file]
}
});
Object.defineProperty(inputEl, 'files', {
value: [file]
});
fireEvent.drop(inputEl);
This triggers the upload, but I keep getting the following error:
Cannot read property 'files' of undefined
at AjaxUploader._this.onFileDrop (node_modules/rc-upload/lib/AjaxUploader.js:108:63)
How can I test Ant Design's Upload?