Last active
September 15, 2023 10:55
-
-
Save amabes/88324d68690e0e7b8e313cd0cafaa219 to your computer and use it in GitHub Desktop.
Simplified example to demonstrate how to Mock a FileList for unit testing purposes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method to test | |
public uploadFileList(files: FileList) { | |
// whatever | |
} | |
// Test | |
it("uploadFileList", () => { | |
const blob = new Blob([""], { type: "text/html" }); | |
blob["lastModifiedDate"] = ""; | |
blob["name"] = "filename"; | |
const file = <File>blob; | |
const fileList = { | |
0: file, | |
1: file, | |
length: 2, | |
item: (index: number) => file | |
}; | |
const spy = spyOn(service, "uploadFileList").and.returnValue([]); | |
expect(service.uploadFileList(fileList)).toEqual([]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Additional typing of blob was required.