Option 1: Using DataTransfer Constructor
describe('Component', () => {
const getFileList = () => {
const dt = new DataTransfer();
dt.items.add(new File([], 'file.csv'));
return dt.files;
};
it('should mock fileList', () => {
component.fileList = getFileList();
});
});
Option 2: Mocking Filelist with Blob
describe('Component', () => {
const getFileList = () => {
const blob = new Blob([""], { type: "text/html" });
blob["lastModifiedDate"] = "";
blob["name"] = "filename";
const file = <File>blob;
const fileList: FileList = {
0: file,
1: file,
length: 2,
item: (index: number) => file
};
return fileList;
};
it('should mock fileList', () => {
component.fileList = getFileList();
});
});
Happy coding!