Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

401
Views
Creating new File in Typescript returns empty type even if type was specified

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.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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' });
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!