Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

403
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda