我正在尝试用NestJS为文件上传API创建swagger文档。
这是我目前在我的控制器中拥有的:
@ApiTags('files')
@Controller('files')
export class FilesController {
@ApiConsumes('multipart/form-data')
@ApiCreatedResponse({description: "This api creates a file in the system"})
@Post('upload')
我目前正在对我的NestJS服务进行单元测试。我的实体名为'User‘,我建立了一个基本服务,允许我通过在控制器中建立的GET和POST端点与MS SQL服务器进行交互。
虽然我能够模拟服务中使用的Repository,但我无法在必须调用getConection()的方法中建立模拟getConnection。
当我尝试用npm run test:watch进行单元测试时,我得到了ConnectionNotFoundError: Connection "default" was not found.的错误,我已经研究过(实际上,取自) ,但这篇文章似乎没有详细说明一个没有
我正在尝试对文件上传进行单元测试,但似乎遗漏了一些东西。
控制器在httpPost处理程序中包含以下相当标准的块:
foreach (string file in Request.Files) {
var postedFile = Request.Files[file] as HttpPostedFileBase;
if (postedFile.ContentLength == 0)
continue;
var fileName = "~/Uploaded/" + Path.GetFileName(postedFile.FileName)
在NestJS应用程序启动时,我创建了几个db表(使用TypeORM),并为此编写了服务文件init-db.service.ts。服务文件实现OnApplicationBootstrap接口,并在应用程序完全启动和引导之后调用onApplicationBootstrap方法。我试图为服务文件编写单元测试,但在创建测试模块时无法解决PinoLogger依赖。请查看下面的示例代码:
服务文件init-db.service.ts:
import {ConfigService} from '@nestjs/config';
import {PinoLogger} from 'n
我已经开始使用NestJS,并且有一个关于单元测试中的模拟警卫的问题。我正在尝试测试一个基本的HTTP controller,它有一个方法保护附加到它。
我的问题开始于我向卫队注入了一项服务(我需要为警卫提供ConfigService )。
运行测试时,DI无法解析“保护”
● AppController › root › should return "Hello World!"
Nest can't resolve dependencies of the ForceFailGuard (?). Please make sure that the argu
我有一个NestJS项目,我需要编写我的服务的单元测试。
我有一个名为BigQueryService的服务,它使用@google/bigquery访问大查询数据集并执行查询。我还有另一个服务(让我们称之为MyService),它的任务是根据其他逻辑构建我需要的查询,并将其传递给BigQueryService,从它接收查询结果并将其返回给控制器,控制器将反过来通过端点发送数据。
我需要为MyService编写单元测试,为此,我需要以一种不需要它解决BigQueryService的依赖关系的方式来模拟BigQueryService。以下是我的一些代码:
bigquery.service.ts:
i
我试图上传一个文件从一个角应用程序到一个nestjs后端,但控制器得到一个未定义的文件。这是角文件服务:
async create(file: File): Promise<string> {
// With console.log I can see file is defined
// file comes directly from the input file (event.target.files[0])
const formData: FormData = new FormData();
form