我正在尝试编写一个上传测试。但我并没有低估如何正确使用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)