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

303
Vistas
jest testing in file upload multer

I have below method in my controller.

 @Post('upload')
    @UseInterceptors(
        FileInterceptor('image', {
            storage: diskStorage({
                destination: './uploads',
                filename(_, file, callback) {
                    const randomName = Array(32)
                        .fill(null)
                        .map(() => Math.round(Math.random() * 16).toString(16))
                        .join('');
                    return callback(null, `${randomName}${extname(file.originalname)}`);
                },
            }),
        })
    )
    uploadFile(@UploadedFile() file) {
        return {
            url: `http://localhost:2300/api/inventory/uploads/${file.filename}`,
            originalFileName: `${file.originalname}`,
        };
    }

it is working perfectly. I wrote below jest test case for same.

   it('Single file upload', async () => {
            const response = await controller.uploadFile(mockFile);
            const fileService = new InventoryController(service);
            expect(response).toBeTruthy();
            expect(response).toStrictEqual(
            expect.objectContaining({
                        originalFileName: expect.any(String),
                        url: expect.any(String),
                    }),
            );
        });

this is becoming successful but coverage is getting failed for below line.

 @UseInterceptors(
            FileInterceptor('image', {
                storage: diskStorage({
                    destination: './uploads',
                    filename(_, file, callback) {
                        const randomName = Array(32)
                            .fill(null)
                            .map(() => Math.round(Math.random() * 16).toString(16))
                            .join('');
                        return callback(null, `${randomName}${extname(file.originalname)}`);
                    },
                }),
            })
        )
       

can you help me how can I test the same , please. means annotation coverage is failing. actually I am not able to define code for coverage in jest file

What parameter I should add in my test file and pass to cover it?

about 4 years ago · Juan Pablo Isaza
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