Skip to content

Commit 6ca4735

Browse files
committed
docs: mocking lib-storage Upload for small files
Fixes #228
1 parent 6d098fc commit 6ca4735

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,25 @@ const query = await ddb.send(new QueryCommand({
306306

307307
#### Lib Storage Upload
308308

309-
To mock `@aws-sdk/lib-storage` `Upload` you need to mock
310-
at least two commands: `CreateMultipartUploadCommand` and `UploadPartCommand`
309+
To mock `@aws-sdk/lib-storage` `Upload` you need to mock all commands
311310
used [under the hood](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-storage/src/Upload.ts):
312311

313312
```typescript
314313
import {S3Client, CreateMultipartUploadCommand, UploadPartCommand} from '@aws-sdk/client-s3';
315314
import {Upload} from "@aws-sdk/lib-storage";
316315

317316
const s3Mock = mockClient(S3Client);
317+
318+
// for big files upload:
318319
s3Mock.on(CreateMultipartUploadCommand).resolves({UploadId: '1'});
319320
s3Mock.on(UploadPartCommand).resolves({ETag: '1'});
320321

322+
// for small files upload:
323+
s3ClientMock.on(PutObjectCommand).callsFake(async (input, getClient) => {
324+
getClient().config.endpoint = () => ({hostname: ""}) as any;
325+
return {};
326+
});
327+
321328
const s3Upload = new Upload({
322329
client: new S3Client({}),
323330
params: {

0 commit comments

Comments
 (0)