I try to generate a mocked File for an Angular unit test and I face some problems.
Here is my code, on top of spec file:
let content = "Hello Zip";
let data = new Blob([content], { type: 'application/zip' });
let arrayOfBlob = new Array<Blob>();
arrayOfBlob.push(data);
let applicationZip = new File(arrayOfBlob, "Mock.zip");
If I try to do:
console.log(applicationZip);
Here is the result:
lastModified: 1492785142174
lastModifiedDate: Fri Apr 21 2017 10:32:22 GMT-0400
name:"Mock.zip"
size:9
type: ""
webkitRelativePath:""
proto: File
On of the method I want to create a test for must check the validity of file's mime type.
With my code, the type is always null. I tried to set it to plain/text for example and it doesn't change anything.
So I guess my File mock creation is somehow incorrect but I can't figure the error.
Specify the type as part of the File constructor. File
accepts a third parameter where you can specify the type:
let applicationZip = new File(arrayOfBlob, "Mock.zip", { type: 'application/zip' });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With