Skip to content

Commit

Permalink
docs: getting calls of a specified command readme and jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
m-radzikowski committed Oct 31, 2021
1 parent 8a3558f commit 7019790
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ In action:
- [DynamoDB DocumentClient](#dynamodb-documentclient)
- [Lib Storage Upload](#lib-storage-upload)
- [Paginated operations](#paginated-operations)
- [Inspect](#inspect)
- [API Reference](#api-reference)
- [AWS Lambda example](#aws-lambda-example)
- [Caveats](#caveats)
Expand Down Expand Up @@ -212,20 +213,6 @@ snsMock
});
```

Inspect received calls:

```typescript
snsMock.calls(); // all received calls
snsMock.call(0); // first received call
```

Under the hood, the library uses [Sinon.js](https://sinonjs.org/) `stub`.
You can get the stub instance to configure and use it directly:

```typescript
const snsSendStub = snsMock.send;
```

#### DynamoDB DocumentClient

You can mock the `DynamoDBDocumentClient` just like any other Client:
Expand Down Expand Up @@ -299,6 +286,35 @@ for await (const page of paginator) {
}
```

### Inspect

Inspect received calls:

```typescript
snsMock.calls(); // all received calls
snsMock.call(0); // first received call
```

Get calls of a specified command:

```typescript
snsMock.commandCalls(PublishCommand)
```

Get calls of a specified command with given payload
(you can force strict matching by passing third param `strict: true`):

```typescript
snsMock.commandCalls(PublishCommand, {Message: 'My message'})
```

Under the hood, the library uses [Sinon.js](https://sinonjs.org/) `stub`.
You can get the stub instance to configure and use it directly:

```typescript
const snsSendStub = snsMock.send;
```

## API Reference

See the [full API Reference](https://m-radzikowski.github.io/aws-sdk-client-mock/).
Expand Down
6 changes: 6 additions & 0 deletions src/awsClientStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export class AwsStub<TInput extends object, TOutput extends MetadataBearer> impl
return this.send.getCall(n);
}

/**
* Returns recorded calls of given Command only.
* @param commandType Command type to match
* @param input Command payload to match
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match)
*/
commandCalls<TCmd extends AwsCommand<any, any>,
TCmdInput extends TCmd extends AwsCommand<infer TIn, any> ? TIn : never,
TCmdOutput extends TCmd extends AwsCommand<any, infer TOut> ? TOut : never,
Expand Down

0 comments on commit 7019790

Please sign in to comment.