how can cover FileInterceptor lines of code in unit test case nestjs

Viewed 18

I have mention below method in my controller.What parameter I should add in my test file and pass to cover it?

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

)

How i can cover these lines of code in test nestjs using jest. In whole controller only these line of code missing in coverage area.

1 Answers

Either pull the callback to a separate location so you can test it directly, or test it using an e2e test and actually sending the request into the server.

Related