Set a permanent mock response that will be used after all one-time handlers are consumed.
Partial output object to return when the command is called
The command stub for chaining
Set a permanent mock rejection that will be used after all one-time handlers are consumed.
Error object or error message string
The command stub for chaining
Set a permanent custom handler function that will be used after all one-time handlers are consumed.
Add a one-time mock response that will be consumed in order.
Partial output object to return
The command stub for chaining
Add a one-time mock rejection that will be consumed in order.
Error object or error message string
The command stub for chaining
Add a one-time custom handler that will be consumed in order.
Set a permanent stream response for S3-like operations.
String, Buffer, or Readable stream
The command stub for chaining
Set a one-time stream response for S3-like operations.
String, Buffer, or Readable stream
The command stub for chaining
Set a permanent mock response with a delay in milliseconds.
Partial output object to return
Delay in milliseconds before resolving
The command stub for chaining
Set a permanent mock rejection with a delay in milliseconds.
Error object or error message string
Delay in milliseconds before rejecting
The command stub for chaining
Reject with an S3 NoSuchKey error.
Optionalkey: stringOptional key name for error message
The command stub for chaining
Reject with an S3 NoSuchBucket error.
Optionalbucket: stringOptional bucket name for error message
The command stub for chaining
Reject with an AccessDenied error.
Optionalresource: stringOptional resource name for error message
The command stub for chaining
Reject with a DynamoDB ResourceNotFound error.
Optionalresource: stringOptional resource name for error message
The command stub for chaining
Reject with a DynamoDB ConditionalCheckFailed error.
The command stub for chaining
Reject with a Throttling error.
The command stub for chaining
Reject with an InternalServerError.
The command stub for chaining
Set paginated responses for AWS pagination patterns.
Tokens are automatically set to the last item of each page, which works for both DynamoDB (object tokens) and S3 (object tokens).
Array of items to paginate (use marshalled items for DynamoDB)
Optionaloptions: PaginatorOptionsPagination configuration options
The command stub for chaining
import { marshall } from '@aws-sdk/util-dynamodb';
const users = [
{ id: "user-1", name: "Alice" },
{ id: "user-2", name: "Bob" }
];
const marshalledUsers = users.map(u => marshall(u));
dynamoMock.on(ScanCommand).resolvesPaginated(marshalledUsers, {
pageSize: 1,
tokenKey: "LastEvaluatedKey",
inputTokenKey: "ExclusiveStartKey"
});
// LastEvaluatedKey will be the marshalled last item (object, not string)
const result = await client.send(new ScanCommand({ TableName: "Users" }));
// result.LastEvaluatedKey = { id: { S: "user-1" }, name: { S: "Alice" } }
const objects = [
{ Key: 'file1.txt', Size: 100 },
{ Key: 'file2.txt', Size: 200 }
];
s3Mock.on(ListObjectsV2Command).resolvesPaginated(objects, {
pageSize: 1,
itemsKey: "Contents",
tokenKey: "NextContinuationToken",
inputTokenKey: "ContinuationToken"
});
// NextContinuationToken will be the last object from the page
const result = await client.send(new ListObjectsV2Command({ Bucket: "bucket" }));
// result.NextContinuationToken = { Key: 'file1.txt', Size: 100 }
Load response from a file. JSON files are parsed, others returned as strings.
Path to the file to load
The command stub for chaining
Command stub for configuring mock behaviors for a specific AWS SDK command. Provides a fluent API for setting up various mock responses and behaviors.
Example: Basic usage
Example: Chaining multiple behaviors