小编lui*_*ckx的帖子

如何用玩笑来模拟 S3?

我正在尝试编写一个上传测试。但我并没有低估如何正确使用jest.mock('aws-sdk')

export class S3Service {
  private readonly s3: S3;
  private readonly bucket: string;
  constructor(private readonly configService: ConfigService) {
    this.s3 = new S3({
      accessKeyId: this.configService.get(''),
      secretAccessKey: this.configService.get(''),
      region: this.configService.get(''),
    });
    this.bucket = this.configService.get('');
  }
async upload(name: string, contentType: string, buffer: Buffer): Promise<string> {
    const upload = await this.s3.upload({params...}).promise();
    return upload;
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3 jestjs aws-sdk-nodejs nestjs

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

amazon-s3 ×1

aws-sdk-nodejs ×1

javascript ×1

jestjs ×1

nestjs ×1